# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
354455 | superadi04 | Job Scheduling (CEOI12_jobs) | Java | 1100 ms | 58272 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.io.*;
import java.util.*;
public class jobs {
static int n, d, m;
static Pair[] requests;
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());
requests = new Pair[m];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < m; i++) {
requests[i] = new Pair(Integer.parseInt(st.nextToken()), i + 1);
}
Arrays.sort(requests, (r1, r2) -> r1.a - r2.a);
// Binary search on the answer
int lo = 0, hi = n;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (check(mid)) {
hi = mid;
} else {
lo = mid + 1;
}
}
// Print answer
System.out.println(lo);
int days = 0;
for (int i = 0; i < m; i += lo) {
days++;
int j = i;
while (j < m && j < i + lo) {
System.out.print(requests[j].b + " ");
j++;
}
System.out.println(0);
}
// Print out the remaining zeroes
while (days < n) {
days++;
System.out.println(0);
}
}
static boolean check(int delay) {
int days = 0;
for (int i = 0; i < m; i += delay) {
days++;
int j = i;
while (j < m && j < i + delay) {
if (requests[j].a + d >= days) {
j++;
} else {
return false;
}
}
}
return days <= n;
}
static class Pair {
int a, b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |