# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
508893 | williamli | Job Scheduling (CEOI12_jobs) | Java | 1098 ms | 65540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.PriorityQueue;
public class jobs {
public static int n, d, m;
public static PriorityQueue<Integer> jobs;
public static void main(String[] args) throws IOException {
// BufferedReader br = new BufferedReader(new FileReader(".in"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(".out")));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
String[] in = br.readLine().split(" ");
n = Integer.parseInt(in[0]);
d = Integer.parseInt(in[1]);
m = Integer.parseInt(in[2]);
jobs = new PriorityQueue<>();
HashMap<Integer, ArrayList<Integer>> timeid = new HashMap<>();
in = br.readLine().split(" ");
for(int i = 0;i < m;i++) {
int cur = Integer.parseInt(in[i]);
jobs.add(cur);
if(!timeid.containsKey(cur)) timeid.put(cur, new ArrayList<>());
timeid.get(cur).add(i);
}
System.out.println(timeid);
int a = 0, b = 1000000;
while(a != b){
int mid = (a + b) / 2;
if(check(mid)) b = mid;
else a = mid + 1;
}
PriorityQueue<Integer> pq = new PriorityQueue<>();
System.out.println(a);
pw.println(a);
for(int i = 1;i <= n;i++){
while(!jobs.isEmpty() && jobs.peek() == i) {
pq.add(i + d);
jobs.poll();
}
for(int j = 0;j < a;j++) {
if(!pq.isEmpty()) {
int cur = pq.poll() - d;
System.out.print((timeid.get(cur).get(0) + 1) + " ");
timeid.get(cur).remove(0);
}
}
System.out.println(0);
}
pw.close();
}
public static boolean check(int test){
PriorityQueue<Integer> pq = new PriorityQueue<>(), job2 = new PriorityQueue<>(jobs);
for(int i = 0;i <= n;i++){
if(job2.isEmpty() && pq.isEmpty()) return true;
if(!pq.isEmpty() && pq.peek() < i) return false;
while(!job2.isEmpty() && job2.peek() == i) {
pq.add(i + d);
job2.poll();
}
for(int j = 0;j < test;j++) if(!pq.isEmpty()) pq.poll();
}
return true;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |