# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119453 | johu | Job Scheduling (CEOI12_jobs) | Java | 403 ms | 46032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.*;
public class jobs {
static int[] Cn; // Job counts per day
static int[] requests; // Flat array of all job requests
static int[] startIndices; // Start indices for each day's jobs in `requests`
static int n, m, d;
public static boolean test(int k) {
int dd = 1, r = 0;
for (int x = 1; x <= n; x++) {
if (Cn[x] == 0) continue;
if (dd < x - d) {
dd = x - d;
r = 0;
}
dd += (Cn[x] + r) / k;
r = (Cn[x] + r) % k;
if (dd > x + 1 || (dd == x + 1 && r > 0)) {
return false;
}
}
return true;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
d = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
Cn = new int[n + 1];
requests = new int[m];
startIndices = new int[n + 2]; // Extra space for boundary checking
int index = 0;
for (int i = 0; i < m; i++) {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
int a = Integer.parseInt(st.nextToken()) + d;
if (a <= n) { // Only store valid jobs within bounds
requests[index++] = i + 1; // Store job index (1-based)
Cn[a]++;
}
}
// Compute start indices for each day
int offset = 0;
for (int x = 1; x <= n; x++) {
startIndices[x] = offset;
offset += Cn[x];
}
startIndices[n + 1] = offset; // Sentinel for boundary checks
// Compute lower and upper bounds for binary search
int left = 1, sol = m, r = 0;
for (int x = 1; x <= n; x++) {
if (Cn[x] == 0) continue;
int bound = (Cn[x] + d) / (d + 1);
left = Math.max(left, bound);
}
while (left < sol) {
int mid = (left + sol) / 2;
if (test(mid)) {
sol = mid;
} else {
left = mid + 1;
}
}
System.out.println(sol);
// Output the schedule
StringBuilder output = new StringBuilder();
int dc = 1, dd = 1, x = 1;
int reqIdx = startIndices[1]; // Start of jobs for the first day
while (dd <= n) {
if (reqIdx >= startIndices[x + 1]) {
x++;
while (x <= n && startIndices[x] == startIndices[x + 1]) x++;
if (x > n) break;
reqIdx = startIndices[x];
}
if (dd < x - d) {
output.append("0\n");
dd++;
dc = 1;
} else {
output.append(requests[reqIdx++]).append(" ");
if (++dc > sol) {
dc = 1;
dd++;
output.append("0\n");
}
}
}
if (dc > 1) {
dd++;
output.append("0\n");
}
while (dd++ <= n) {
output.append("0\n");
}
System.out.print(output);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |