Submission #3422963


Source Code Expand

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int[] S;
    static int[] E;

    public static void main(String[] args) {
        FastScanner fc = new FastScanner(System.in);
        N = fc.nextInt();
        S = new int[N];
        E = new int[N];
        for (int i = 0; i < N; i++) {
            String se = fc.next();
            S[i] = Integer.parseInt(se.substring(0, 4));
            E[i] = Integer.parseInt(se.substring(5));
        }

        PrintWriter pw = new PrintWriter(System.out);
        for (Range range : solve()) {
            pw.println( String.format("%04d", range.start) + "-" + String.format("%04d", range.end));
        }
        pw.flush();
    }

    static List<Range> solve() {
        int[] imos = new int[2400+2];
        for (int i = 0; i < N; i++) {
            int s = S[i] / 5 * 5; // floor
            int e = (E[i] + 4) / 5 * 5; // ceil
            if( String.valueOf(e).endsWith("60") ) {
                e += 40;
            }
            imos[s]++;
            imos[e+1]--;
        }

        List<Range> ans = new ArrayList<>();
        int cur = 0;
        int start = -1;
        for (int i = 0; i < imos.length; i++) {
            cur += imos[i];
            if( start == -1 && cur > 0 ) {
                start = i;
            } else if( start != -1 && cur == 0 ) {
                ans.add( new Range(start, i-1) );
                start = -1;
            }
        }
        return ans;
    }

    static class Range {
        int start;
        int end;

        public Range(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}

Submission Info

Submission Time
Task D - 感雨時刻の整理
User kusomushi
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 3405 Byte
Status AC
Exec Time 175 ms
Memory 33852 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 78 ms 18388 KB
00_sample_02.txt AC 77 ms 19284 KB
00_sample_03.txt AC 79 ms 18772 KB
cho_cho_chokudai.txt AC 169 ms 28808 KB
chokudai_ga_cho.txt AC 166 ms 30672 KB
test_01.txt AC 101 ms 20820 KB
test_02.txt AC 95 ms 21716 KB
test_03.txt AC 95 ms 23124 KB
test_04.txt AC 97 ms 20820 KB
test_05.txt AC 95 ms 23764 KB
test_06.txt AC 80 ms 18900 KB
test_07.txt AC 82 ms 18388 KB
test_08.txt AC 81 ms 20052 KB
test_09.txt AC 89 ms 20692 KB
test_10.txt AC 86 ms 20308 KB
test_11.txt AC 88 ms 21332 KB
test_12.txt AC 85 ms 19540 KB
test_13.txt AC 80 ms 18260 KB
test_14.txt AC 90 ms 21076 KB
test_15.txt AC 88 ms 20052 KB
test_16.txt AC 81 ms 21456 KB
test_17.txt AC 87 ms 18000 KB
test_18.txt AC 81 ms 18772 KB
test_19.txt AC 85 ms 20180 KB
test_20.txt AC 84 ms 20176 KB
test_21.txt AC 161 ms 28460 KB
test_22.txt AC 161 ms 33852 KB
test_23.txt AC 156 ms 32684 KB
test_24.txt AC 158 ms 30764 KB
test_25.txt AC 168 ms 32864 KB
test_26.txt AC 161 ms 32428 KB
test_27.txt AC 169 ms 32372 KB
test_28.txt AC 152 ms 32520 KB
test_29.txt AC 76 ms 18132 KB
test_30.txt AC 81 ms 20820 KB
test_31.txt AC 122 ms 24532 KB
test_32.txt AC 77 ms 21460 KB
test_33.txt AC 155 ms 26156 KB
test_34.txt AC 76 ms 19924 KB
test_35.txt AC 81 ms 17620 KB
test_36.txt AC 163 ms 29960 KB
test_37.txt AC 175 ms 32608 KB
test_38.txt AC 167 ms 32260 KB
test_39.txt AC 164 ms 30324 KB
test_40.txt AC 166 ms 31900 KB
test_41.txt AC 158 ms 30468 KB
test_42.txt AC 169 ms 31968 KB
test_43.txt AC 169 ms 30688 KB