답안 #343976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343976 2021-01-05T01:23:41 Z vijay Job Scheduling (CEOI12_jobs) Java 11
컴파일 오류
0 ms 0 KB
import java.io.*;
import java.util.*;

public class jobs {

    static int N, D, M;
    static Pair[] requests;
    public static void main(String[] args) throws IOException, FileNotFoundException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("job.out")));

        N = in.nextInt();
        D = in.nextInt();
        M = in.nextInt();

        requests = new Pair[M];

        for(int i = 0; i < M; i++){
            requests[i] = new Pair(in.nextInt(), i + 1);
        }

        Arrays.sort(requests);

        int a = 1;
        int b = 1000000;
        while(a != b){
            int mid = (a + b)/2;
            if(works(mid)){
                b = mid;
            } else {
                a = mid + 1;
            }
        }

        String[] returns = new String[N];
        int machineIdx = 0;
        int[] lastTask = new int[a];
        for(int i = 0; i < M; i++){
            lastTask[machineIdx] = Math.max(lastTask[machineIdx] + 1, requests[i].a);
            int idx = lastTask[machineIdx] - 1;
            if(returns[idx] == null){
                returns[idx] = String.valueOf(requests[i].b);
            } else {
                returns[idx] += " " + requests[i].b;
            }
            machineIdx++;
            machineIdx %= a;
        }

        System.out.println(a);
        for(int i = 0; i < N; i++){
            if(returns[i] != null){
                System.out.println(returns[i] + " 0");
            } else {
                System.out.println("0");
            }
        }
    }

    public static boolean works(int machines){
        int[] lastTask = new int[machines];
        int machineIdx = 0;
        for(int i = 0; i < M; i++){
            lastTask[machineIdx] = Math.max(lastTask[machineIdx] + 1, requests[i].a);
            if(lastTask[machineIdx] - requests[i].a > D){
                return false;
            }
            machineIdx++;
            machineIdx %= machines;
        }

        return true;
    }

    static class Pair implements Comparable<Pair>{
        int a, b;
        public Pair(int a, int b){
            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p){
            return a - p.a;
        }
    }
}

Compilation message

jobs.java:12: error: cannot find symbol
        N = in.nextInt();
            ^
  symbol:   variable in
  location: class jobs
jobs.java:13: error: cannot find symbol
        D = in.nextInt();
            ^
  symbol:   variable in
  location: class jobs
jobs.java:14: error: cannot find symbol
        M = in.nextInt();
            ^
  symbol:   variable in
  location: class jobs
jobs.java:19: error: cannot find symbol
            requests[i] = new Pair(in.nextInt(), i + 1);
                                   ^
  symbol:   variable in
  location: class jobs
4 errors