# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
675369 | wisePigOnTheMoon | Job Scheduling (CEOI12_jobs) | Java | 559 ms | 65536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.util.*;
import java.io.*;
public class jobs {
private static final int DAY = 1, ID = 0;
public static void main(String[] args) throws Exception {
Reader in = new Reader();
int days = in.nextInt();
int d = in.nextInt();
int totalJobs = in.nextInt();
int[] jobs = new int[days];
ArrayList[] ids = new ArrayList[days];
for (int i = 0; i < days; i++) {
ids[i] = new ArrayList<Integer>();
}
for (int i = 0; i < totalJobs; i++) {
int requestDay = in.nextInt() - 1;
jobs[requestDay]++;
ids[requestDay].add(i+1);
}
for (int i = 0; i < days; i++) {
ids[i].trimToSize();
}
int l = 1;
int r = totalJobs;
while (l < r) {
int mid = (l + r)/2;
if (checkValid(mid, totalJobs, days, d, jobs)) {
r = mid;
} else {
l = mid + 1;
}
}
System.out.println(l);
printSchedule(l, days, ids);
}
public static boolean checkValid(int numMachines, int totalJobs, int days, int d, int[] jobs) {
int start = 0, current = 0, toDo = jobs[start], machines = numMachines;
int done = 0;
while (current < days && (current - start) <= d) {
if (toDo > machines) {
done += machines;
toDo -= machines;
current++;
machines = numMachines;
} else {
machines -= toDo;
done += toDo;
if (machines == 0) {
current++;
machines = numMachines;
}
start++;
toDo = start < days ? jobs[start] : 0;
}
if (start > current) {
current = start;
machines = numMachines;
}
}
if (current - start > d || done < totalJobs) {
return false;
}
return true;
}
public static void printSchedule(int numMachines, int days, ArrayList[] ids) {
StringBuilder sb = new StringBuilder();
int done = 0, start = 0, lid = 0;
for (int current = 0; current < days; current++) {
while (done < numMachines && start <= current) {
if (lid >= ids[start].size()) {
start++;
lid = 0;
continue;
}
sb.append(ids[start].get(lid++));
sb.append(" ");
done++;
}
sb.append("0\n");
done = 0;
}
System.out.println(sb.toString());
}
static class Reader //FastReader//
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |