# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
513007 | ryankim0709 | Job Scheduling (CEOI12_jobs) | Java | 1095 ms | 53448 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.util.*;
import java.io.*;
public class jobs {
static class Job implements Comparable<Job> {
int index;
int day;
public Job(int index, int day) {
this.index = index;
this.day = day;
}
public int compareTo(Job a) {
return this.day - a.day;
}
}
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()); // # of days organization works
int D = Integer.parseInt(st.nextToken()); // Maximum permitted delay
int M = Integer.parseInt(st.nextToken()); // # of job requests
Job[] jobs = new Job[M];
st = new StringTokenizer(br.readLine());
for (int x = 0; x < M; x++) {
jobs[x] = new Job(x + 1, Integer.parseInt(st.nextToken()));
}
Arrays.sort(jobs);
int lo = 1;
int hi = 20;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (simulate(mid, jobs, N, D)) {
hi = mid;
} else {
lo = mid + 1;
}
}
System.out.println(hi);
System.out.println(getAnswer(hi, jobs, N));
}
public static String getAnswer(int machines, Job[] jobs, int lines) {
String ans = "";
int index = 0;
for (int x = 0; x < lines; x++) {
if (index == jobs.length) {
ans += "0\n";
} else {
for (int y = 0; y < machines; y++) {
if (index == jobs.length) {
ans += "0 ";
} else {
ans += jobs[index].index + " ";
index++;
}
}
ans += "0\n";
}
}
return ans.substring(0, ans.length() - 1);
}
public static boolean simulate(int machines, Job[] jobs, int days, int max) {
if (machines * days < jobs.length) {
return false;
}
int dayNum = 1;
int index = 0;
int customer = 0;
while (dayNum != days + 1) {
if (index == jobs.length) {
return true;
}
Job a = jobs[index];
if (a.day > dayNum) { // Not that day yet
dayNum++;
continue;
}
if (dayNum - a.day > max) {
return false;
} // Maximum delay is the current day - job assigned
customer++;
if (customer == machines) {
dayNum++;
customer = 0;
index++;
continue;
}
index++;
}
return true;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |