답안 #965051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965051 2024-04-18T04:21:55 Z QuantumPi Job Scheduling (CEOI12_jobs) Java 11
컴파일 오류
0 ms 0 KB
import java.io.*;
import java.util.*;
 
public class JobScheduling {
    public static int[] nums;
    public static Queue[] h;
    public static int d;
    public static void main(String[] args) {
        Scanner fin = new Scanner(System.in);

        int n = fin.nextInt();
        d = fin.nextInt();
        int m = fin.nextInt();

        nums = new int[n-d];
        h = new Queue[n-d];
        for (int i=0; i<n-d; i++) {
            h[i] = new PriorityQueue<>(); 
        }
        for (int i=0; i<m; i++) {
            int num = fin.nextInt()-1;
            nums[num]++;
            h[num].add(i+1);
        }
        int low = 0;
        int high = 10;
        while (low < high) {
            int mid = (low+high)/2;
            if (works(mid)) {
                high = mid;
            }
            else {
                low = mid+1;
            }
        }
        print(low);

        fin.close();
    }

    public static boolean works(int numMachines) {
        Queue<Integer> q = new PriorityQueue<>();
        int currentDay = 0;
        for (int i=0; i<nums[currentDay]; i++) {
            q.add(currentDay);
        }
        while (!q.isEmpty()) {
            for (int i=0; i<numMachines; i++) {
                if (!q.isEmpty()) {
                    if (q.poll()+d < currentDay) {
                        return false;
                    }
                }
            }
            currentDay++;
            if (currentDay < nums.length) {
                for (int i=0; i<nums[currentDay]; i++) {
                    q.add(currentDay);
                }
            }
        }
        return true;
    }

    public static void print(int numMachines) {
        Queue<Integer> q = new PriorityQueue<>();
        int currentDay = 0;
        String ans = numMachines+"";
        for (int i=0; i<nums[currentDay]; i++) {
            q.add(currentDay);
        }
        while (!q.isEmpty()) {
            //System.out.println(q+" "+currentDay);
            //System.out.println(ans);
            ans += "\n";
            for (int i=0; i<numMachines; i++) {
                if (!q.isEmpty()) {
                    int num = q.poll();
                    ans += h[num].poll()+" ";
                }
            }
            currentDay++;
            ans += "0";
            if (currentDay < nums.length) {
                for (int i=0; i<nums[currentDay]; i++) {
                    q.add(currentDay);
                }
            }
        }
        System.out.println(ans);
    }
}

Compilation message

jobs.java:4: error: class JobScheduling is public, should be declared in a file named JobScheduling.java
public class JobScheduling {
       ^
Note: jobs.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error