Submission #675336

#TimeUsernameProblemLanguageResultExecution timeMemory
675336wisePigOnTheMoonJob Scheduling (CEOI12_jobs)Java
60 / 100
591 ms65536 KiB
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, jobs)) { r = mid; } else { l = mid + 1; } } System.out.println(l); printer(l, days, jobs, ids); } public static boolean checkValid(int numMachines, int days, int d, int[] jobs) { int start = 0, current = 0, toDo = jobs[start], machines = numMachines; while (current < days && (current - start) <= d) { if (toDo > machines) { toDo -= machines; current++; machines = numMachines; } else { machines -= 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) { return false; } if (toDo > 0 || start < days) return false; return true; } public static void printer(int numMachines, int days, int[] jobs, ArrayList<ArrayList<Integer>> ids) { StringBuilder sb = new StringBuilder(); int start = 0, current = 0, toDo = jobs[start], machines = numMachines, jobStart = 0; while (current < days) { if (toDo > machines) { for (int i = 0; i < machines; i++) { sb.append(ids.get(start).get(jobStart++)); sb.append(" "); } toDo -= machines; current++; sb.append("0\n"); machines = numMachines; } else { machines -= toDo; for (int i = 0; i < toDo; i++) { sb.append(ids.get(start).get(jobStart++)); sb.append(" "); } if (machines == 0) { current++; machines = numMachines; sb.append("0\n"); } start++; jobStart = 0; toDo = start < days ? jobs[start] : 0; } if (start > current) { current = start; machines = numMachines; sb.append("0\n"); } } 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; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...