답안 #438920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
438920 2021-06-29T00:00:21 Z Airy Job Scheduling (CEOI12_jobs) Java 11
0 / 100
211 ms 12308 KB
import java.util.*;
 
class jobschedule {
    public static Pair [] arr;
    public static int m;
    public static int d;
    public static int n;
    public static int [] times;
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
 
        n = s.nextInt();
        d = s.nextInt();
        m = s.nextInt();
 
        arr = new Pair [m];
 
        for (int i = 0; i < m; i++) {
            arr[i] = new Pair (s.nextInt(), i + 1);
        }
 
        Arrays.sort(arr);
 
        int a = 1, b = m;
        int mid = 1;
        
        while (a != b) {
            mid = (a + b) / 2;
 
            if (simulate(mid)) {
                b = mid;
            }
 
            else {
                a = mid + 1;
            }
        }
 
        if (!simulate(mid)) {
            simulate(mid + 1);
            mid++;
            System.out.println(mid);
        }
 
        else {
            simulate(mid);
            System.out.println(mid);
        }
 
        int pos = 0;
        int dayf = 1;
        boolean done = false;
      
      	//System.out.println("here");
 
        for (int i = 0; i < n; i++) {
            //System.out.println(pos + mid + "h" + done);
            if (done) {
                System.out.println(0);
                continue;
            }
 
            if ((pos + mid) >= m) {
                done = true;
            }
 
            for (int j = pos; j < m; j++) {
                //System.out.println(j + " " + dayf + " " + times[j]);
                if (!(dayf == times[j])) {
                    dayf++;
                    pos = j;
                    break;
                }
 
                System.out.print(arr[j].index + " ");
            }
 
            System.out.print(0);
 
            System.out.println();
        }
    }
 
    public static boolean simulate (int x) {
        int counter = 1;
        int day = 1;
 
        times = new int [m];
 
        for (int i = 0; i < m; i++) {
            times[i] = day;
 
            counter++;
 
            if (counter > x) {
                counter = 1;
                day++;
            }
        }
 
        //System.out.println(Arrays.toString(times) + " " + x);
 
        for (int i = 0; i < m; i++) {
            if (times[i] - arr[i].sorter > d) {
                return false;
            }
        }
 
        return true;
    }
 
    private static class Pair implements Comparable<Pair> {
        int sorter;
        int index;
 
        public Pair(int location, int index) {
            this.sorter = location;
            this.index = index;
        }
        
        @Override
        public int compareTo(Pair o) {
            return sorter - o.sorter;
        }
 
        @Override
        public boolean equals (Object other) {
            Pair nother = (Pair) other;
            return nother.sorter == sorter;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 169 ms 12140 KB Execution failed because the return code was nonzero
2 Runtime error 190 ms 12100 KB Execution failed because the return code was nonzero
3 Runtime error 185 ms 12104 KB Execution failed because the return code was nonzero
4 Runtime error 170 ms 11820 KB Execution failed because the return code was nonzero
5 Runtime error 190 ms 12072 KB Execution failed because the return code was nonzero
6 Runtime error 176 ms 11920 KB Execution failed because the return code was nonzero
7 Runtime error 169 ms 12256 KB Execution failed because the return code was nonzero
8 Runtime error 178 ms 11968 KB Execution failed because the return code was nonzero
9 Runtime error 174 ms 12072 KB Execution failed because the return code was nonzero
10 Runtime error 189 ms 11964 KB Execution failed because the return code was nonzero
11 Runtime error 168 ms 12308 KB Execution failed because the return code was nonzero
12 Runtime error 174 ms 12160 KB Execution failed because the return code was nonzero
13 Runtime error 177 ms 11940 KB Execution failed because the return code was nonzero
14 Runtime error 211 ms 11896 KB Execution failed because the return code was nonzero
15 Runtime error 175 ms 11900 KB Execution failed because the return code was nonzero
16 Runtime error 165 ms 12220 KB Execution failed because the return code was nonzero
17 Runtime error 173 ms 11984 KB Execution failed because the return code was nonzero
18 Runtime error 171 ms 12196 KB Execution failed because the return code was nonzero
19 Runtime error 165 ms 12132 KB Execution failed because the return code was nonzero
20 Runtime error 192 ms 11944 KB Execution failed because the return code was nonzero