답안 #1119463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1119463 2024-11-27T04:59:14 Z johu Job Scheduling (CEOI12_jobs) Java 11
0 / 100
156 ms 26768 KB
import java.io.*;
import java.util.*;

public class jobs {
    static class Pair implements Comparable<Pair> {
        int fr, sc;

        Pair(int fr, int sc) {
            this.fr = fr;
            this.sc = sc;
        }

        @Override
        public int compareTo(Pair other) {
            return Integer.compare(this.fr, other.fr);
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        Pair[] a = new Pair[m + 2];
        for (int i = 1; i <= m; i++) {
            st = new StringTokenizer(br.readLine());
            int fr = Integer.parseInt(st.nextToken());
            a[i] = new Pair(fr, i);
        }
        a[m + 1] = new Pair((int) 1e9, 0); // Dummy pair

        Arrays.sort(a, 1, m + 1); // Sort only the relevant range

        int l = 0, r = m;

        while (r - l > 1) {
            int mid = (l + r) / 2;
            int p = 1;
            boolean valid = true;

            for (int i = 1; i <= n; i++) {
                if (a[p].fr + d < i) {
                    valid = false;
                    break;
                }
                int cnt = 0;
                while (cnt < mid && p <= m && a[p].fr <= i) {
                    cnt++;
                    p++;
                }
            }

            if (p > m) {
                r = mid;
            } else {
                l = mid;
            }
        }

        System.out.println(r);
        int p = 1;
        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= n; i++) {
            int cnt = 0;
            while (cnt < r && p <= m && a[p].fr <= i) {
                sb.append(a[p].sc).append(" ");
                cnt++;
                p++;
            }
            sb.append(0).append("\n");
        }

        System.out.print(sb);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 118 ms 14280 KB Execution failed because the return code was nonzero
2 Runtime error 126 ms 14636 KB Execution failed because the return code was nonzero
3 Runtime error 136 ms 14464 KB Execution failed because the return code was nonzero
4 Runtime error 129 ms 14608 KB Execution failed because the return code was nonzero
5 Runtime error 132 ms 14628 KB Execution failed because the return code was nonzero
6 Runtime error 120 ms 14816 KB Execution failed because the return code was nonzero
7 Runtime error 119 ms 14124 KB Execution failed because the return code was nonzero
8 Runtime error 117 ms 14312 KB Execution failed because the return code was nonzero
9 Runtime error 115 ms 12604 KB Execution failed because the return code was nonzero
10 Runtime error 119 ms 12760 KB Execution failed because the return code was nonzero
11 Runtime error 115 ms 14432 KB Execution failed because the return code was nonzero
12 Runtime error 125 ms 15644 KB Execution failed because the return code was nonzero
13 Runtime error 127 ms 18048 KB Execution failed because the return code was nonzero
14 Runtime error 137 ms 19800 KB Execution failed because the return code was nonzero
15 Runtime error 135 ms 19228 KB Execution failed because the return code was nonzero
16 Runtime error 132 ms 22908 KB Execution failed because the return code was nonzero
17 Runtime error 143 ms 26524 KB Execution failed because the return code was nonzero
18 Runtime error 156 ms 26768 KB Execution failed because the return code was nonzero
19 Runtime error 152 ms 25484 KB Execution failed because the return code was nonzero
20 Runtime error 155 ms 25180 KB Execution failed because the return code was nonzero