Submission #1119551

#TimeUsernameProblemLanguageResultExecution timeMemory
1119551johuJob Scheduling (CEOI12_jobs)Java
Compilation error
0 ms0 KiB
import java.io.*; import java.util.*; public class jobs { public static void main(String[] args) throws IOException { FastInputReader reader = new FastInputReader(System.in); int n = reader.nextInt(); // Number of days int d = reader.nextInt(); // Delay allowed int m = reader.nextInt(); // Number of events if (m <= 300000) { // Use the ArrayList-based implementation for smaller cases handleSmallCases(reader, n, d, m); } else { // Use the C++ equivalent logic for larger cases handleLargeCasesCppEquivalent(reader, n, d, m); } } private static void handleSmallCases(FastInputReader reader, int n, int d, int m) throws IOException { List<Pair> a = new ArrayList<>(m + 2); for (int i = 1; i <= m; i++) { a.add(new Pair(reader.nextInt(), i)); } a.add(new Pair(1000000000, 0)); // Dummy pair for boundary a.sort(Comparator.naturalOrder()); int l = 0, r = m; while (r - l > 1) { int mid = (l + r) / 2; int p = 0; for (int i = 1; i <= n; i++) { if (a.get(p).fr + d < i) { break; } int cnt = 0; while (cnt < mid && p < m && a.get(p).fr <= i) { cnt++; p++; } } if (p >= m) { r = mid; } else { l = mid; } } System.out.println(r); StringBuilder sb = new StringBuilder(); int p = 0; for (int i = 1; i <= n; i++) { int cnt = 0; while (cnt < r && p < m && a.get(p).fr <= i) { sb.append(a.get(p).sc).append(" "); cnt++; p++; } sb.append("0\n"); } System.out.print(sb); } private static void handleLargeCasesCppEquivalent(FastInputReader reader, int n, int d, int m) throws IOException { ArrayList<Integer>[] c = new ArrayList[n]; for (int i = 0; i < n; i++) { c[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { int t = reader.nextInt() - 1; c[t].add(i); } Pair[] in = new Pair[m]; List<Integer>[] ans = new ArrayList[n]; for (int i = 0; i < n; i++) { ans[i] = new ArrayList<>(); } // Check function translated from C++ Function<Integer, Boolean> check = x -> { int cur = 0, len = 0; for (int i = 0; i < n; i++) { if (cur < len && in[cur].first <= i) { return false; } int end = i + d + 1; for (int cVal : c[i]) { in[len++] = new Pair(end, cVal); } int left = x; while (left-- > 0 && cur < len) { ans[i].add(in[cur++].second); } } return cur == len; }; int lo = 1, hi = m; while (lo < hi) { int mid = (lo + hi) / 2; if (check.apply(mid)) { hi = mid; } else { lo = mid + 1; } } check.apply(lo); System.out.println(lo); for (List<Integer> list : ans) { for (int x : list) { System.out.print((x + 1) + " "); } System.out.println(0); } } static class Pair { int first, second; Pair(int first, int second) { this.first = first; this.second = second; } } static class FastInputReader { private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; public FastInputReader(InputStream in) { din = new DataInputStream(in); buffer = new byte[1 << 16]; // 64 KB buffer bufferPointer = bytesRead = 0; } public int nextInt() throws IOException { int ret = 0; byte c = 0; while (bufferPointer < bytesRead || refillBuffer()) { c = buffer[bufferPointer++]; if (c > ' ') break; // Skip non-digit } boolean neg = (c == '-'); if (neg) c = buffer[bufferPointer++]; while (c >= '0' && c <= '9') { ret = ret * 10 + (c - '0'); if (bufferPointer == bytesRead && !refillBuffer()) break; c = buffer[bufferPointer++]; } return neg ? -ret : ret; } private boolean refillBuffer() throws IOException { bytesRead = din.read(buffer, 0, buffer.length); bufferPointer = 0; return bytesRead > 0; } } }

Compilation message (stderr)

jobs.java:28: error: incompatible types: inference variable T has incompatible bounds
        a.sort(Comparator.naturalOrder());
         ^
    lower bounds: Comparable<? super T>
    lower bounds: Pair
  where T is a type-variable:
    T extends Comparable<? super T> declared in method <T>naturalOrder()
jobs.java:37: error: cannot find symbol
                if (a.get(p).fr + d < i) {
                            ^
  symbol:   variable fr
  location: class Pair
jobs.java:41: error: cannot find symbol
                while (cnt < mid && p < m && a.get(p).fr <= i) {
                                                     ^
  symbol:   variable fr
  location: class Pair
jobs.java:60: error: cannot find symbol
            while (cnt < r && p < m && a.get(p).fr <= i) {
                                               ^
  symbol:   variable fr
  location: class Pair
jobs.java:61: error: cannot find symbol
                sb.append(a.get(p).sc).append(" ");
                                  ^
  symbol:   variable sc
  location: class Pair
jobs.java:89: error: cannot find symbol
        Function<Integer, Boolean> check = x -> {
        ^
  symbol:   class Function
  location: class jobs
Note: jobs.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
6 errors