# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
675239 | wisePigOnTheMoon | Job Scheduling (CEOI12_jobs) | Java | 618 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.*;
import java.io.*;
public class jobs {
public static void main(String[] args) throws Exception {
Reader in = new Reader();
int days = in.nextInt();
int d = in.nextInt();
int m = in.nextInt();
int[] jobs = new int[days];
ArrayList<ArrayList<Integer>> ids = new ArrayList<>();
for (int i = 0; i < days; i++) {
ids.add(new ArrayList<Integer>());
}
for (int i = 0; i < m; i++) {
int assign = in.nextInt();
jobs[assign - 1]++;
ids.get(assign - 1).add(i + 1);
}
int l = 0;
int r = m;
while (l < r) {
int mid = (l + r)/2;
if (checkValid(mid, days, d, days, jobs)) {
r = mid;
} else {
l = mid + 1;
}
}
System.out.println(l);
printer(l, days, d, days, jobs, ids);
}
public static boolean checkValid(int macs, int days, int d, int n, int[] jobs) {
int i = 0;
int count = 1;
int jobCount = 0;
while (count <= days && i < n) {
int work = 0;
while (work < macs && i < n) {
if (jobCount < jobs[i]) {
if (i + 1 > count) {
break;
}
if (count > i + 1 + d) {
return false;
}
work++;
jobCount++;
if (jobCount == jobs[i]) {
jobCount = 0;
i++;
}
} else {
i++;
}
}
count++;
}
if (i < n) {
return false;
}
return true;
}
public static void printer(int macs, int days, int d, int n, int[] jobs, ArrayList<ArrayList<Integer>> ids) {
StringBuilder sb = new StringBuilder();
int i = 0;
int count = 1;
int jobCount = 0;
while (count <= days && i < n) {
int work = 0;
while (work < macs && i < n) {
if (jobCount < jobs[i]) {
if (i + 1 > count) {
break;
}
sb.append(ids.get(i).get(jobCount));
sb.append(" ");
work++;
jobCount++;
if (jobCount == jobs[i]) {
jobCount = 0;
i++;
}
} else {
i++;
}
}
sb.append("0\n");
count++;
}
while (count <= days) {
sb.append("0\n");
count++;
}
System.out.println(sb);
}
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;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |