Submission #4828560
Source Code Expand
import static java.util.Comparator.*; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { static public void main(String[] args) { // 標準入力取得用 Scanner scan = new Scanner(System.in); // 雨が降った時間のメモの回数を取得する int size = scan.nextInt(); // 雨が降った時間のメモの内容を取得する(yymm-yymm) List<String> list = new ArrayList<>(size); for (int i = 0; i < size; i++) { list.add(scan.next()); } // 雨の開始時間を用いて昇順にソートする list.sort(naturalOrder()); // 条件判断に用いる開始時間と終了時間を設定する int start = 9999; int end = -1; // 雨が振った時間のメモのリストを全て回す for (String data : list) { // 雨の開始時間と終了時間を取得する String[] record = data.split("-"); int rainStart = Integer.parseInt(record[0]); int rainEnd = Integer.parseInt(record[1]); // 雨の開始時間を5分単位の時刻に丸める(1148⇒1145) rainStart -= rainStart % 5; // 雨の終了時間を5分単位の時刻に丸める(1401⇒1405) if (rainEnd % 5 > 0) { rainEnd += 5 - rainEnd % 5; } // 雨の終了時間を5分単位に丸めた際、時間が変わった場合の対応(1456⇒1460⇒1500) if (rainEnd % 100 == 60) { rainEnd += 40; } // メモ書きの時間(雨の開始時間が終了時間より大きい場合)が被っていなければ出力する // ※マージした場合(被った場合)で途中で出力されない場合は最後で出力する if (rainStart > end) { // 開始時間に何も設定されていない(=9999)場合は、まだ出力しない if (start != 9999) { // 一旦、これ以上マージされない(被らない)ため、出力する System.out.println(String.format("%04d", start) + "-" + String.format("%04d", end)); } // 雨の開始時間を開始時間に設定する start = rainStart; // 終了時間を初期化する(新しく終了時間を設定するため) // この後で設定する終了時間は絶対大きくなるため end = -1; } // 雨の終了時間が、既に設定されている終了時間より大きい場合、雨の終了時間を終了時間に設定する if (end < rainEnd) { end = rainEnd; } } // 雨の開始時間と終了時間を出力する System.out.println(String.format("%04d", start) + "-" + String.format("%04d", end)); // 標準入力のリソースを閉じる scan.close(); } }
Submission Info
Submission Time | |
---|---|
Task | D - 感雨時刻の整理 |
User | tomoyukio |
Language | Java8 (OpenJDK 1.8.0) |
Score | 100 |
Code Size | 2716 Byte |
Status | AC |
Exec Time | 382 ms |
Memory | 48700 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 | 94 ms | 18900 KB |
00_sample_02.txt | AC | 93 ms | 21204 KB |
00_sample_03.txt | AC | 94 ms | 19412 KB |
cho_cho_chokudai.txt | AC | 323 ms | 47196 KB |
chokudai_ga_cho.txt | AC | 291 ms | 42932 KB |
test_01.txt | AC | 135 ms | 22100 KB |
test_02.txt | AC | 136 ms | 21588 KB |
test_03.txt | AC | 141 ms | 22100 KB |
test_04.txt | AC | 125 ms | 19156 KB |
test_05.txt | AC | 129 ms | 21972 KB |
test_06.txt | AC | 108 ms | 21460 KB |
test_07.txt | AC | 105 ms | 19152 KB |
test_08.txt | AC | 103 ms | 20692 KB |
test_09.txt | AC | 122 ms | 22356 KB |
test_10.txt | AC | 136 ms | 22484 KB |
test_11.txt | AC | 132 ms | 18512 KB |
test_12.txt | AC | 121 ms | 21588 KB |
test_13.txt | AC | 119 ms | 21844 KB |
test_14.txt | AC | 124 ms | 19268 KB |
test_15.txt | AC | 134 ms | 21324 KB |
test_16.txt | AC | 107 ms | 21460 KB |
test_17.txt | AC | 120 ms | 21460 KB |
test_18.txt | AC | 107 ms | 20944 KB |
test_19.txt | AC | 127 ms | 21332 KB |
test_20.txt | AC | 120 ms | 21204 KB |
test_21.txt | AC | 370 ms | 45680 KB |
test_22.txt | AC | 334 ms | 40512 KB |
test_23.txt | AC | 343 ms | 40088 KB |
test_24.txt | AC | 332 ms | 44320 KB |
test_25.txt | AC | 331 ms | 44188 KB |
test_26.txt | AC | 366 ms | 46288 KB |
test_27.txt | AC | 307 ms | 44720 KB |
test_28.txt | AC | 361 ms | 44784 KB |
test_29.txt | AC | 95 ms | 19792 KB |
test_30.txt | AC | 112 ms | 19668 KB |
test_31.txt | AC | 193 ms | 26916 KB |
test_32.txt | AC | 100 ms | 19028 KB |
test_33.txt | AC | 292 ms | 39144 KB |
test_34.txt | AC | 93 ms | 19796 KB |
test_35.txt | AC | 113 ms | 21332 KB |
test_36.txt | AC | 331 ms | 43004 KB |
test_37.txt | AC | 382 ms | 47248 KB |
test_38.txt | AC | 369 ms | 44136 KB |
test_39.txt | AC | 333 ms | 46212 KB |
test_40.txt | AC | 337 ms | 48700 KB |
test_41.txt | AC | 289 ms | 42668 KB |
test_42.txt | AC | 363 ms | 44128 KB |
test_43.txt | AC | 319 ms | 43312 KB |