# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
705741 | hex | Job Scheduling (CEOI12_jobs) | Java | 1094 ms | 50128 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.io.*;
import java.util.*;
class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(problemName + ".out");
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) {}
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
public class jobs {
static int[] days;
static int numReq;
static int delay;
static class Req implements Comparable<Req> {
int day;
int id;
public Req (int day, int id) {
this.day = day;
this.id = id;
}
public int compareTo (Req r) {
return Integer.compare(this.day, r.day);
}
}
static boolean valid (int numMachine) {
int numRes = days[1];
//Index issues possibly?
for (int day = 2; day < days.length; day++) {
numRes -= Math.min(numMachine, numReq);
if (days[day] > 0 && Math.ceil(numRes / numMachine) > delay) return false;
numRes += days[day];
}
return true;
}
public static void main (String[] args) throws IOException {
Kattio io = new Kattio();
int numDays = io.nextInt();
delay = io.nextInt();
numReq = io.nextInt();
Req[] reqs = new Req[numReq];
days = new int[numDays + 1]; //1 INDEXED
for (int r = 0; r < numReq; r++) {
reqs[r] = new Req(io.nextInt(), r + 1);
days[reqs[r].day]++;
}
Arrays.sort(reqs);
int lt = 1;
int rt = numReq + 1;
int mid;
while (lt < rt) {
mid = (lt + rt) / 2;
if (valid(mid)) {
rt = mid;
} else {
lt = mid + 1;
}
}
//At the end, just loop through reqs in sorted order and print out lt ids in a single line, followed by a 0
io.println(lt);
for (int d = 1; d < reqs[0].day; d++) {
io.println(0);
}
int r = 0;
for (int d = reqs[0].day; d <= numDays; d++) {
int num = 0;
while (r < reqs.length && num < lt) {
io.print(reqs[r].id + " ");
r++;
num++;
}
io.println(0);
//out.println();
}
//out.println(valid(1, delay, reqs));
io.close();
}
}
//Check N = 1.
//Check for needed longs.
//Use Long.parseLong() instead of Integer.parseInt().
//Use Long.MAX_VALUE instead of Integer.MAX_VALUE.
//Use an int array of ids instead of a boolean array of visited nodes during DFS.
//Declare a class variable instead of a method parameter, as passing by value could result in a TLE.
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |