Submission #3310681
Source Code Expand
object Main { sealed trait TimeRangeListClass { def hasNext: Boolean } case object TimeRangeListEmpty extends TimeRangeListClass { def hasNext: Boolean = false } class TimeRangeList( var timeRange: TimeRange, var next: TimeRangeListClass ) extends TimeRangeListClass { def hasNext: Boolean = { next match { case TimeRangeListEmpty => false case _ => true } } def insert( other: TimeRange ): TimeRangeList = { if ( timeRange.isOverlapping( other ) ) { val ( t, n ) = merge( timeRange.combine( other ) ) this.timeRange = t this.next = n this } else { if ( timeRange.startTime < other.startTime ) { next match { case TimeRangeListEmpty => this.next = new TimeRangeList(other, TimeRangeListEmpty) () case t: TimeRangeList => if ( t.timeRange.startTime > other.startTime && ! t.timeRange.isOverlapping( other )) { this.next = new TimeRangeList( other, t) () } else { t.insert(other) () } } this } else { new TimeRangeList( other, this ) } } } def merge( other: TimeRange ): ( TimeRange, TimeRangeListClass ) = { next match { case TimeRangeListEmpty => ( other, TimeRangeListEmpty ) case t: TimeRangeList => if ( t.timeRange.isOverlapping( other ) ) { t.merge( other.combine( t.timeRange ) ) } else { ( other, next ) } } } def print(): Unit = { val startStr = f"${timeRange.startTime}%04d" val endStr = f"${timeRange.endTime}%04d" println(s"$startStr-$endStr") next match { case TimeRangeListEmpty => () case t: TimeRangeList => t.print() } } } def main(args: Array[String]): Unit = { val N = io.StdIn.readLine().toInt val elms = io.StdIn.readLine().split( "-", 2) val timeRange = TimeRange( makeStartTime( elms( 0 ) ), makeEndTime( elms( 1 ) )) var timeRangeList: TimeRangeList = new TimeRangeList( timeRange, TimeRangeListEmpty ) ( 2 to N ).foreach{ _ => val elms = io.StdIn.readLine().split( "-", 2) val timeRange = TimeRange( makeStartTime( elms( 0 ) ), makeEndTime( elms( 1 ) )) timeRangeList = timeRangeList.insert( timeRange ) } timeRangeList.print() } case class TimeRange( startTime: Int, endTime: Int ) { def isOverlapping( timerange: TimeRange ): Boolean = { val maxOfStartTime = if ( startTime > timerange.startTime ) { startTime } else { timerange.startTime } val minOfEndTime = if (endTime < timerange.endTime) { endTime } else { timerange.endTime } if (maxOfStartTime == minOfEndTime) { true } else if (maxOfStartTime < minOfEndTime) { true } else { false } } def combine(timerange: TimeRange): TimeRange = { val minOfStartTime = if (startTime < timerange.startTime) { startTime } else { timerange.startTime } val maxOfEndTime = if ( endTime > timerange.endTime) { endTime } else { timerange.endTime } TimeRange(minOfStartTime, maxOfEndTime) } } def makeStartTime( timeString: String ): Int = { val hour = timeString.substring( 0, 2 ).toInt val minute = timeString.substring(2).toInt val oneDegreeInMinute = minute % 10 val roundMinute = if ( oneDegreeInMinute < 5 ) { minute - oneDegreeInMinute } else { minute - oneDegreeInMinute + 5 } hour * 100 + roundMinute } def makeEndTime( timeString: String ): Int = { val hour = timeString.substring( 0, 2 ).toInt val minute = timeString.substring(2).toInt val oneDegreeInMinute = minute % 10 if ( oneDegreeInMinute == 0 ) { hour * 100 + minute } else if ( 0 < oneDegreeInMinute && oneDegreeInMinute <= 5 ) { ( hour * 100 ) + minute - oneDegreeInMinute + 5 } else { val tmp = minute - oneDegreeInMinute + 10 if ( tmp >= 60 ) { ( hour + 1 ) * 100 } else { hour * 100 + tmp } } } }
Submission Info
Submission Time | |
---|---|
Task | D - 感雨時刻の整理 |
User | yasuki111 |
Language | Scala (2.11.7) |
Score | 100 |
Code Size | 4566 Byte |
Status | AC |
Exec Time | 670 ms |
Memory | 41164 KB |
Judge Result
Set Name | all | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
all | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, cho_cho_chokudai.txt, chokudai_ga_cho.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 336 ms | 25688 KB |
00_sample_02.txt | AC | 320 ms | 23348 KB |
00_sample_03.txt | AC | 322 ms | 25256 KB |
cho_cho_chokudai.txt | AC | 667 ms | 36868 KB |
chokudai_ga_cho.txt | AC | 640 ms | 39080 KB |
test_01.txt | AC | 367 ms | 25284 KB |
test_02.txt | AC | 355 ms | 25284 KB |
test_03.txt | AC | 360 ms | 23484 KB |
test_04.txt | AC | 369 ms | 25660 KB |
test_05.txt | AC | 360 ms | 23616 KB |
test_06.txt | AC | 334 ms | 25280 KB |
test_07.txt | AC | 328 ms | 25408 KB |
test_08.txt | AC | 323 ms | 27212 KB |
test_09.txt | AC | 343 ms | 25284 KB |
test_10.txt | AC | 345 ms | 25424 KB |
test_11.txt | AC | 343 ms | 27080 KB |
test_12.txt | AC | 329 ms | 25028 KB |
test_13.txt | AC | 327 ms | 25276 KB |
test_14.txt | AC | 337 ms | 25392 KB |
test_15.txt | AC | 341 ms | 25260 KB |
test_16.txt | AC | 324 ms | 25384 KB |
test_17.txt | AC | 340 ms | 25400 KB |
test_18.txt | AC | 333 ms | 25384 KB |
test_19.txt | AC | 332 ms | 25288 KB |
test_20.txt | AC | 336 ms | 25376 KB |
test_21.txt | AC | 645 ms | 40612 KB |
test_22.txt | AC | 639 ms | 37412 KB |
test_23.txt | AC | 626 ms | 38580 KB |
test_24.txt | AC | 643 ms | 38724 KB |
test_25.txt | AC | 630 ms | 38720 KB |
test_26.txt | AC | 628 ms | 38960 KB |
test_27.txt | AC | 637 ms | 41164 KB |
test_28.txt | AC | 630 ms | 39124 KB |
test_29.txt | AC | 319 ms | 25284 KB |
test_30.txt | AC | 321 ms | 25300 KB |
test_31.txt | AC | 496 ms | 31508 KB |
test_32.txt | AC | 317 ms | 25116 KB |
test_33.txt | AC | 647 ms | 36860 KB |
test_34.txt | AC | 316 ms | 25292 KB |
test_35.txt | AC | 335 ms | 25280 KB |
test_36.txt | AC | 620 ms | 38720 KB |
test_37.txt | AC | 670 ms | 39268 KB |
test_38.txt | AC | 659 ms | 38268 KB |
test_39.txt | AC | 649 ms | 38772 KB |
test_40.txt | AC | 654 ms | 39012 KB |
test_41.txt | AC | 651 ms | 39132 KB |
test_42.txt | AC | 651 ms | 37408 KB |
test_43.txt | AC | 635 ms | 38812 KB |