제출 #705722

#제출 시각아이디문제언어결과실행 시간메모리
705722hexJob Scheduling (CEOI12_jobs)Java
40 / 100
1089 ms53976 KiB
import java.io.*; import java.util.*; public class jobs { static Req[] reqs; 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) { //Comparing by id is not needed here. return Integer.compare(this.day, r.day); } } //Check if changing reqs to a static array will be fater static boolean valid (int numMachine, int delay) { int day = reqs[0].day; int r = 0; int res = 0; //res.clear(); while (r < reqs.length) { int num = 0; while (res < r && num < numMachine) { if (reqs[res].day + delay < day) return false; res++; num++; } r += numMachine; day++; } return true; } public static void main (String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(reader.readLine()); int days = Integer.parseInt(st.nextToken()); int delay = Integer.parseInt(st.nextToken()); int numReq = Integer.parseInt(st.nextToken()); reqs = new Req[numReq]; st = new StringTokenizer(reader.readLine()); for (int r = 0; r < numReq; r++) { reqs[r] = new Req(Integer.parseInt(st.nextToken()), r + 1); } Arrays.sort(reqs); int lt = 1; int rt = numReq; int mid; while (lt < rt) { mid = (lt + rt) / 2; if (valid(mid, delay)) { 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 out.println(lt); for (int d = 1; d < reqs[0].day; d++) { out.println(0); } int r = 0; for (int d = reqs[0].day; d <= days; d++) { int num = 0; while (r < reqs.length && num < lt) { out.print(reqs[r].id + " "); r++; num++; } out.println(0); //out.println(); } //out.println(valid(1, delay, reqs)); out.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...