Submission #3411767


Source Code Expand

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class Main {

    private  final String DATE_STR = "20190101";
    private List<String> result = new ArrayList<>();
    private DateTimeFormatter iPattern = DateTimeFormatter.ofPattern("uuuuMMddHHmm");
    private DateTimeFormatter oPattern = DateTimeFormatter.ofPattern("HHmm");

    public static void main(String[] args) {
        new Main().exec();
    }

    private void exec() {
        Scanner sc = new Scanner(System.in);
        int lines = sc.nextInt();
        Map<String, String> times = new TreeMap<>();
        for (int i = 0; i < lines; i++) {
            String[] time = sc.next().split("-");
            if (times.containsKey(time[0])) {
                if (Integer.parseInt(times.get(time[0])) < Integer.parseInt(time[1])) {
                    times.put(time[0], time[1]);
                }
            } else {
                times.put(time[0], time[1]);
            }
        }
        LocalDateTime beforeStart = null;
        LocalDateTime beforeEnd = null;

        for (String start : times.keySet()) {
            LocalDateTime curStart = LocalDateTime.parse(DATE_STR + start, iPattern);
            curStart = curStart.minusMinutes(curStart.getMinute() % 5);
            LocalDateTime curEnd = LocalDateTime.parse(DATE_STR + (times.get(start)), iPattern);
            if (0 < curEnd.getMinute() % 5) {
                curEnd = curEnd.plusMinutes(5 - curEnd.getMinute() % 5);
            }
            if (beforeStart == null) {
                beforeStart = curStart;
                beforeEnd = curEnd;
            } else if (curStart.isAfter(beforeEnd)) {
                addResult(beforeStart, beforeEnd);
                beforeStart = curStart;
                beforeEnd = curEnd;
            } else if (curEnd.isAfter(beforeEnd)) {
                beforeEnd = curEnd;
            }
        }

        addResult(beforeStart, beforeEnd);
        for (String res : result) {
            System.out.println(res);
        }
    }

    private void addResult(LocalDateTime start, LocalDateTime end) {
        String endHm = oPattern.format(end);
        if (endHm.equals("0000")) {
            endHm = "2400";
        }
        result.add(oPattern.format(start) + "-" + endHm);
    }
}

Submission Info

Submission Time
Task D - 感雨時刻の整理
User mak64
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 2380 Byte
Status AC
Exec Time 601 ms
Memory 45252 KB

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 48
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 226 ms 26432 KB
00_sample_02.txt AC 196 ms 27092 KB
00_sample_03.txt AC 196 ms 27220 KB
cho_cho_chokudai.txt AC 426 ms 41560 KB
chokudai_ga_cho.txt AC 601 ms 45252 KB
test_01.txt AC 247 ms 29516 KB
test_02.txt AC 244 ms 25164 KB
test_03.txt AC 227 ms 25040 KB
test_04.txt AC 236 ms 29396 KB
test_05.txt AC 235 ms 27208 KB
test_06.txt AC 254 ms 25296 KB
test_07.txt AC 227 ms 27092 KB
test_08.txt AC 216 ms 26960 KB
test_09.txt AC 225 ms 25168 KB
test_10.txt AC 235 ms 27348 KB
test_11.txt AC 225 ms 27088 KB
test_12.txt AC 262 ms 27468 KB
test_13.txt AC 239 ms 26832 KB
test_14.txt AC 276 ms 26960 KB
test_15.txt AC 298 ms 28720 KB
test_16.txt AC 224 ms 26956 KB
test_17.txt AC 279 ms 27808 KB
test_18.txt AC 250 ms 27088 KB
test_19.txt AC 263 ms 27856 KB
test_20.txt AC 269 ms 27340 KB
test_21.txt AC 564 ms 45164 KB
test_22.txt AC 505 ms 40344 KB
test_23.txt AC 544 ms 42680 KB
test_24.txt AC 568 ms 42796 KB
test_25.txt AC 584 ms 42040 KB
test_26.txt AC 470 ms 42440 KB
test_27.txt AC 404 ms 44700 KB
test_28.txt AC 469 ms 42300 KB
test_29.txt AC 189 ms 28744 KB
test_30.txt AC 217 ms 27472 KB
test_31.txt AC 332 ms 33108 KB
test_32.txt AC 198 ms 24788 KB
test_33.txt AC 466 ms 42576 KB
test_34.txt AC 200 ms 26956 KB
test_35.txt AC 242 ms 27220 KB
test_36.txt AC 557 ms 45048 KB
test_37.txt AC 479 ms 40452 KB
test_38.txt AC 515 ms 42588 KB
test_39.txt AC 456 ms 42180 KB
test_40.txt AC 512 ms 44408 KB
test_41.txt AC 453 ms 42528 KB
test_42.txt AC 466 ms 44600 KB
test_43.txt AC 461 ms 42884 KB