Submission #2440653
Source Code Expand
import java.util.*; public class Main { private static class Term implements Comparable<Term> { private int startTime; private int endTime; private Term(int s, int e) { startTime = normalizeStart(s); endTime = normalizeEnd(e); } public int canExtent(Term t) { if (t. startTime < startTime) { throw new RuntimeException("unexpected"); } else { if (endTime < t.startTime) { return Integer.MAX_VALUE; // 範囲外 } else { if (endTime < t.endTime) { return 1; // 時間延長 } else { return 0; // 内包 } } } } public void extent(Term t) { endTime = t.endTime; } private int normalizeStart(int s) { return s - (s % 5); } private int normalizeEnd(int e) { int h = getHour(e); int m = getMinute(e); int a = m % 5; if (0 < a) { a = 5 - a; } if (55 < m) { ++h; m = 0; } else { m += a; } return h * 100 + m; } private int getHour(int t) { return t/ 100; } private int getMinute(int t) { return t % 100; } @Override public int compareTo(Term t) { return (startTime - t.startTime) * 1000 + endTime - t.endTime; } @Override public String toString() { return String.format("%04d-%04d", startTime, endTime); } } public static void main(String... args) { ArrayList<Term> n = normalize(readAllTime(readN()));; for (Term t : n) { System.out.println(t); } } private static ArrayList<Term> normalize(ArrayList<Term> list) { ArrayList<Term> n = new ArrayList<>(); Term last = null; for (Term t : list) { if (last == null) { n.add(t); last = t; continue; } switch(last.canExtent(t)) { case 0: break; case 1: last.extent(t); break; default: n.add(t); last = t; break; } } return n; } private static ArrayList<Term> readAllTime(int N) { ArrayList<Term> l = new ArrayList<>(N); for (int i = 0; i < N; ++i) { l.add(readTime()); } Collections.sort(l); return l; } private static Term readTime() { String[] t = scanString().split("-"); return new Term(Integer.parseInt(t[0]), Integer.parseInt(t[1])); } private static int readN() { int N = scanInt(); if (N < 1 || 30000 < N) { throw new IllegalArgumentException("out of range, N=" + N); } return N; } private static final Scanner SC = new Scanner(System.in); private static int scanInt() { return SC.nextInt(); } private static String scanString() { return SC.next(); } }
Submission Info
Submission Time | |
---|---|
Task | D - 感雨時刻の整理 |
User | herohero |
Language | Java7 (OpenJDK 1.7.0) |
Score | 100 |
Code Size | 2674 Byte |
Status | AC |
Exec Time | 690 ms |
Memory | 48784 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 | 100 ms | 18896 KB |
00_sample_02.txt | AC | 99 ms | 18900 KB |
00_sample_03.txt | AC | 100 ms | 20820 KB |
cho_cho_chokudai.txt | AC | 616 ms | 46188 KB |
chokudai_ga_cho.txt | AC | 649 ms | 48020 KB |
test_01.txt | AC | 129 ms | 19412 KB |
test_02.txt | AC | 130 ms | 22996 KB |
test_03.txt | AC | 130 ms | 19412 KB |
test_04.txt | AC | 128 ms | 19412 KB |
test_05.txt | AC | 129 ms | 19412 KB |
test_06.txt | AC | 131 ms | 21716 KB |
test_07.txt | AC | 113 ms | 19284 KB |
test_08.txt | AC | 111 ms | 21204 KB |
test_09.txt | AC | 159 ms | 20436 KB |
test_10.txt | AC | 148 ms | 19796 KB |
test_11.txt | AC | 145 ms | 19796 KB |
test_12.txt | AC | 131 ms | 21588 KB |
test_13.txt | AC | 116 ms | 19284 KB |
test_14.txt | AC | 144 ms | 24020 KB |
test_15.txt | AC | 149 ms | 19668 KB |
test_16.txt | AC | 115 ms | 21204 KB |
test_17.txt | AC | 154 ms | 22228 KB |
test_18.txt | AC | 120 ms | 23252 KB |
test_19.txt | AC | 136 ms | 19796 KB |
test_20.txt | AC | 141 ms | 19668 KB |
test_21.txt | AC | 660 ms | 46412 KB |
test_22.txt | AC | 655 ms | 42876 KB |
test_23.txt | AC | 654 ms | 44908 KB |
test_24.txt | AC | 664 ms | 44120 KB |
test_25.txt | AC | 680 ms | 46712 KB |
test_26.txt | AC | 689 ms | 46376 KB |
test_27.txt | AC | 648 ms | 48784 KB |
test_28.txt | AC | 688 ms | 47976 KB |
test_29.txt | AC | 99 ms | 16980 KB |
test_30.txt | AC | 108 ms | 19412 KB |
test_31.txt | AC | 395 ms | 28152 KB |
test_32.txt | AC | 106 ms | 21204 KB |
test_33.txt | AC | 646 ms | 41028 KB |
test_34.txt | AC | 99 ms | 20820 KB |
test_35.txt | AC | 123 ms | 19668 KB |
test_36.txt | AC | 656 ms | 43736 KB |
test_37.txt | AC | 677 ms | 44684 KB |
test_38.txt | AC | 690 ms | 45172 KB |
test_39.txt | AC | 679 ms | 46536 KB |
test_40.txt | AC | 676 ms | 46492 KB |
test_41.txt | AC | 585 ms | 46196 KB |
test_42.txt | AC | 631 ms | 45540 KB |
test_43.txt | AC | 601 ms | 48264 KB |