Submission #705739

#TimeUsernameProblemLanguageResultExecution timeMemory
705739hexJob Scheduling (CEOI12_jobs)Java
0 / 100
1081 ms50212 KiB
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]; int numProc = 0; //Index issues possibly? for (int day = 2; day < days.length; day++) { numProc += Math.min(numMachine, numReq); if (numProc == numReq) return true; numRes -= Math.min(numMachine, numReq); if (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 timeMemoryGrader output
Fetching results...