Submission #1183009

#TimeUsernameProblemLanguageResultExecution timeMemory
1183009fyanJob Scheduling (CEOI12_jobs)C++20
Compilation error
0 ms0 KiB
import java.io.*;
import java.util.*;

public class Main {
    static final int MX = (int)1e6 + 6;
    static final int nax = (int)1e5 + 5;

    static Pair[] in = new Pair[MX];
    static ArrayList<Integer>[] C = new ArrayList[nax];
    static ArrayList<Integer>[] ans = new ArrayList[nax];

    static class Pair implements Comparable<Pair> {
        int first, second;

        Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }

        public int compareTo(Pair o) {
            return Integer.compare(this.first, o.first);
        }
    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    static int readInt() throws IOException {
        int v = 0;
        int c = br.read();
        while (c < '0' || c > '9') c = br.read();
        while ('0' <= c && c <= '9') {
            v = v * 10 + (c - '0');
            c = br.read();
        }
        return v;
    }

    static void writeInt(int x, boolean newline) throws IOException {
        if (x == 0) bw.write('0');
        else bw.write(Integer.toString(x));
        if (newline) bw.write("\n");
        else bw.write(" ");
    }

    static boolean check(int x, boolean CREATE, int N, int D) {
        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 c : C[i]) {
                in[len++] = new Pair(end, c);
            }

            if (CREATE) {
                int left = x;
                while (left-- > 0 && cur < len) {
                    ans[i].add(in[cur++].second);
                }
            } else cur = Math.min(len, cur + x);
        }
        return cur == len;
    }

    public static void main(String[] args) throws IOException {
        int N = readInt(), D = readInt(), M = readInt();

        for (int i = 0; i < nax; i++) {
            C[i] = new ArrayList<>();
            ans[i] = new ArrayList<>();
        }

        for (int i = 0; i < M; i++) {
            int t = readInt() - 1;
            C[t].add(i);
        }

        int lo = 1, hi = M;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (check(mid, false, N, D)) hi = mid;
            else lo = mid + 1;
        }

        check(lo, true, N, D);

        writeInt(lo, true);
        for (int i = 0; i < N; i++) {
            for (int x : ans[i]) writeInt(x + 1, false);
            writeInt(0, true);
        }

        bw.flush();
    }
}

Compilation message (stderr)

jobs.cpp:1:1: error: 'import' does not name a type
    1 | import java.io.*;
      | ^~~~~~
jobs.cpp:1:1: note: C++20 'import' only available with '-fmodules-ts', which is not yet enabled with '-std=c++20'
jobs.cpp:2:1: error: 'import' does not name a type
    2 | import java.util.*;
      | ^~~~~~
jobs.cpp:2:1: note: C++20 'import' only available with '-fmodules-ts', which is not yet enabled with '-std=c++20'
jobs.cpp:4:1: error: expected unqualified-id before 'public'
    4 | public class Main {
      | ^~~~~~