Submission #1003735
Source Code Expand
import java.util.Iterator; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] orgArrayOfRange = new String[n]; for (int i = 0; i < n; i++) { orgArrayOfRange[i] = sc.next(); } Set<String> setOfRange = new TreeSet<String>(); for (int i = 0; i < n; i++) { setOfRange.add(roundTimeRange(orgArrayOfRange[i])); } Set<String> arrangedSetOfRange = arrangeRange(setOfRange); Iterator<String> iterator; iterator = arrangedSetOfRange.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } private static Set<String> arrangeRange(Set<String> setOfRange) { Object[] rangeArray = setOfRange.toArray(); Set<String> arrangedSetOfRange = new TreeSet<String>(); String prev_start = null; String prev_end = null; for (int i = 0; i < rangeArray.length; i++) { String current = (String)rangeArray[i]; String current_start = current.substring(0, current.indexOf('-')); String current_end = current.substring(current.indexOf('-') + 1); if (prev_start == null && prev_end == null) { prev_start = current_start; prev_end = current_end; } else { if (current_start.compareTo(prev_end) <= 0) { if (prev_end.compareTo(current_end) <= 0) { prev_end = current_end; } } else { arrangedSetOfRange.add(prev_start + "-" + prev_end); prev_start = current_start; prev_end = current_end; } } } arrangedSetOfRange.add(prev_start + "-" + prev_end); return arrangedSetOfRange; } private static String roundTimeRange(String range) { String start = range.substring(0, range.indexOf('-')); String end = range.substring(range.indexOf('-') + 1); start = roundDownTime(start); end = roundUpTime(end); return start + "-" + end; } private static String roundUpTime(String time) { int hour = Integer.parseInt(time.substring(0, 2)); int minutes = Integer.parseInt(time.substring(2, 4)); if (minutes % 5 != 0) { minutes = minutes + (5 - minutes % 5); if (minutes == 60) { minutes = 0; hour = hour + 1; } } return String.format("%02d", hour) + String.format("%02d", minutes); } private static String roundDownTime(String time) { int minutes = Integer.parseInt(time.substring(2, 4)); minutes = minutes - minutes % 5; return time.substring(0, 2) + String.format("%02d", minutes); } }
Submission Info
Submission Time | |
---|---|
Task | D - 感雨時刻の整理 |
User | taikyokuken |
Language | Java (OpenJDK 1.7.0) |
Score | 100 |
Code Size | 2633 Byte |
Status | AC |
Exec Time | 1376 ms |
Memory | 60464 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 | 248 ms | 22308 KB |
00_sample_02.txt | AC | 241 ms | 22384 KB |
00_sample_03.txt | AC | 242 ms | 22368 KB |
cho_cho_chokudai.txt | AC | 1184 ms | 56624 KB |
chokudai_ga_cho.txt | AC | 1239 ms | 57028 KB |
test_01.txt | AC | 283 ms | 23212 KB |
test_02.txt | AC | 285 ms | 23204 KB |
test_03.txt | AC | 282 ms | 23236 KB |
test_04.txt | AC | 282 ms | 23168 KB |
test_05.txt | AC | 281 ms | 23084 KB |
test_06.txt | AC | 299 ms | 23860 KB |
test_07.txt | AC | 278 ms | 23264 KB |
test_08.txt | AC | 278 ms | 22956 KB |
test_09.txt | AC | 412 ms | 29752 KB |
test_10.txt | AC | 421 ms | 30016 KB |
test_11.txt | AC | 389 ms | 27896 KB |
test_12.txt | AC | 353 ms | 26616 KB |
test_13.txt | AC | 291 ms | 23480 KB |
test_14.txt | AC | 429 ms | 30180 KB |
test_15.txt | AC | 431 ms | 30000 KB |
test_16.txt | AC | 285 ms | 23352 KB |
test_17.txt | AC | 410 ms | 29576 KB |
test_18.txt | AC | 304 ms | 23580 KB |
test_19.txt | AC | 375 ms | 27760 KB |
test_20.txt | AC | 380 ms | 27672 KB |
test_21.txt | AC | 1304 ms | 57284 KB |
test_22.txt | AC | 1235 ms | 57072 KB |
test_23.txt | AC | 1376 ms | 58520 KB |
test_24.txt | AC | 1251 ms | 58100 KB |
test_25.txt | AC | 1270 ms | 56824 KB |
test_26.txt | AC | 1208 ms | 57164 KB |
test_27.txt | AC | 1318 ms | 60464 KB |
test_28.txt | AC | 1197 ms | 56132 KB |
test_29.txt | AC | 239 ms | 22392 KB |
test_30.txt | AC | 254 ms | 22616 KB |
test_31.txt | AC | 832 ms | 46900 KB |
test_32.txt | AC | 252 ms | 22468 KB |
test_33.txt | AC | 1351 ms | 56440 KB |
test_34.txt | AC | 240 ms | 22268 KB |
test_35.txt | AC | 304 ms | 23736 KB |
test_36.txt | AC | 1349 ms | 59500 KB |
test_37.txt | AC | 1203 ms | 57860 KB |
test_38.txt | AC | 1195 ms | 56520 KB |
test_39.txt | AC | 1258 ms | 56776 KB |
test_40.txt | AC | 1316 ms | 59292 KB |
test_41.txt | AC | 1288 ms | 56968 KB |
test_42.txt | AC | 1263 ms | 57088 KB |
test_43.txt | AC | 1202 ms | 57544 KB |