Submission #109199
Source Code Expand
import scala.collection.mutable object Main { def main(args: Array[String]) { val n = readInt val times: Seq[(Time, Time)] = (1 to n) map { i => val (rawS, rawE) = readf2("{0}-{1}") (Time.fromString(rawS.toString), Time.fromString(rawE.toString)) } val periods = times.map(Period.roundTime).sorted(PeriodOrdering) val resultStack = periods.foldLeft(mutable.Stack[Period]())(stackFold) resultStack.toList.reverse.foreach(println) } def stackFold(seq: mutable.Stack[Period], p: Period): mutable.Stack[Period] = { if(seq.isEmpty) seq.push(p) else if(isOverrap(seq.top, p)) { val last = seq.pop seq.push(join(last, p)) } else seq.push(p) seq } def join(fst: Period, snd: Period): Period = { require(fst.start <= snd.start) require(fst.end >= snd.start) Period(fst.start, TimeOrdering.max(fst.end, snd.end)) } def isOverrap(fst: Period, snd: Period): Boolean = { require(fst.start <= snd.start) fst.end >= snd.start } } case class Time(hour: Int, minutes: Int) extends Ordered[Time] { override def toString() = "%02d".format(hour) + "%02d".format(minutes) def compare(that: Time): Int = TimeOrdering.compare(this, that) } object Time { def fromString(str: String): Time = { val hour = str.substring(0, 2).toInt val min = str.substring(2, 4).toInt Time(hour, min) } } object TimeOrdering extends Ordering[Time] { def compare(a: Time, b: Time) = { val hour = a.hour compare b.hour if(hour == 0) a.minutes compare b.minutes else hour } } case class Period(start: Time, end: Time) { override def toString(): String = Array(start, end).mkString("-") } object Period { def roundTime(start: Time, end: Time): Period = { val roundStart = Time(start.hour, round(start.minutes, false)) val roundEndMin = round(end.minutes, true) val roundEnd = Time(end.hour + roundEndMin / 60, roundEndMin % 60) Period(roundStart, roundEnd) } def roundTime(se: (Time, Time)): Period = roundTime(se._1, se._2) /** * round per 5 * @param min: integer * @param isRev: true -> revaluation, false -> devaluation */ def round(min: Int, isRev: Boolean) = { val per5 = min / 5 + (if(min % 5 != 0 && isRev) 1 else 0) per5 * 5 } } object PeriodOrdering extends Ordering[Period] { def compare(a: Period, b: Period) = { val start = a.start compare b.start if(start == 0) a.end compare b.end else start } }
Submission Info
Submission Time | |
---|---|
Task | D - 感雨時刻の整理 |
User | ponkotuy |
Language | Scala (2.9.1) |
Score | 100 |
Code Size | 2584 Byte |
Status | AC |
Exec Time | 1954 ms |
Memory | 60124 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 | 1109 ms | 42732 KB |
00_sample_02.txt | AC | 1106 ms | 42756 KB |
00_sample_03.txt | AC | 1046 ms | 42716 KB |
cho_cho_chokudai.txt | AC | 1704 ms | 59364 KB |
chokudai_ga_cho.txt | AC | 1760 ms | 59620 KB |
test_01.txt | AC | 1092 ms | 43892 KB |
test_02.txt | AC | 1109 ms | 43908 KB |
test_03.txt | AC | 1090 ms | 44032 KB |
test_04.txt | AC | 1131 ms | 43916 KB |
test_05.txt | AC | 1134 ms | 43904 KB |
test_06.txt | AC | 1036 ms | 43268 KB |
test_07.txt | AC | 1024 ms | 43140 KB |
test_08.txt | AC | 1019 ms | 43024 KB |
test_09.txt | AC | 1121 ms | 44280 KB |
test_10.txt | AC | 1159 ms | 44544 KB |
test_11.txt | AC | 1102 ms | 44168 KB |
test_12.txt | AC | 1092 ms | 43744 KB |
test_13.txt | AC | 1065 ms | 43160 KB |
test_14.txt | AC | 1104 ms | 44424 KB |
test_15.txt | AC | 1178 ms | 44668 KB |
test_16.txt | AC | 1049 ms | 43140 KB |
test_17.txt | AC | 1104 ms | 44152 KB |
test_18.txt | AC | 1066 ms | 43264 KB |
test_19.txt | AC | 1144 ms | 43748 KB |
test_20.txt | AC | 1130 ms | 43860 KB |
test_21.txt | AC | 1820 ms | 59624 KB |
test_22.txt | AC | 1787 ms | 59488 KB |
test_23.txt | AC | 1798 ms | 59452 KB |
test_24.txt | AC | 1874 ms | 59316 KB |
test_25.txt | AC | 1878 ms | 60124 KB |
test_26.txt | AC | 1806 ms | 59740 KB |
test_27.txt | AC | 1817 ms | 59600 KB |
test_28.txt | AC | 1773 ms | 59476 KB |
test_29.txt | AC | 1108 ms | 42772 KB |
test_30.txt | AC | 1115 ms | 42872 KB |
test_31.txt | AC | 1433 ms | 55584 KB |
test_32.txt | AC | 1042 ms | 42856 KB |
test_33.txt | AC | 1751 ms | 59880 KB |
test_34.txt | AC | 1014 ms | 42884 KB |
test_35.txt | AC | 1055 ms | 43588 KB |
test_36.txt | AC | 1789 ms | 59572 KB |
test_37.txt | AC | 1885 ms | 59120 KB |
test_38.txt | AC | 1776 ms | 59180 KB |
test_39.txt | AC | 1852 ms | 59352 KB |
test_40.txt | AC | 1781 ms | 59540 KB |
test_41.txt | AC | 1954 ms | 59500 KB |
test_42.txt | AC | 1837 ms | 59812 KB |
test_43.txt | AC | 1718 ms | 59852 KB |