답안 #1119364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1119364 2024-11-27T01:39:07 Z hujo Job Scheduling (CEOI12_jobs) Java 11
5 / 100
1000 ms 65536 KB
    import java.io.*;
    import java.util.*;
     
    public class jobs{
        static int N; static int M;
        static List<Job> jobs;
        static PrintWriter pr;
        public static void main(String []args) throws IOException{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            pr = new PrintWriter(new OutputStreamWriter(System.out));
            StringTokenizer st = new StringTokenizer(br.readLine());
     
            N = Integer.parseInt(st.nextToken()); int D = Integer.parseInt(st.nextToken()); M = Integer.parseInt(st.nextToken());
            jobs = new ArrayList<>();
            st = new StringTokenizer(br.readLine());
            for(int i=1; i<=M; i++){
                int id = Integer.parseInt(st.nextToken());
                jobs.add(new Job(i, id, id+D));
            }
            jobs.sort((j1, j2)->Integer.compare(j1.end, j2.end));
            int minmachine=binsearchLeft(0, M);
            printRes(minmachine);
            pr.close();
        }
        static boolean isGood(int machines){
            Queue<Job> q= new LinkedList<Job>();
            for(Job j: jobs){
                q.offer(j);
            }
            for(int i=1; i<=N; i++){
                int nleft = machines;
                while(nleft>0 && q.peek()!=null){
                    Job top = q.peek();
                    if(top.start >i){
                        break;
                    }
                    else{
                        q.poll();
                        nleft--;
                    }
                }
            }
            if(q.isEmpty()){
                return true;
            }
            else{return false;}
        }
        static void printRes(int min){
          	pr.println(min);
            Queue<Job> q= new LinkedList<Job>();
            for(Job j: jobs){
                q.offer(j);
            }
            for(int i=1; i<=N; i++){
                int nleft = min;
                while(nleft>0 && q.peek()!=null){
                    Job top = q.peek();
                    if(top.start >i){
                        break;
                    }
                    else{
                        pr.print(top.id+" ");
                        q.poll();
                        nleft--;
                    }
                }
                pr.print(0);
                pr.println();
            }
        }
     
     
     
        static int binsearchLeft(int left, int right){
            if(left>right){
                return -1;
            }
            int mid = left + (right-left)/2;
            if(isGood(mid)){
                int res = binsearchLeft(left, mid-1);
                if(res==-1){return mid;}
                else{return res;}
            }
            else{
                return binsearchLeft(mid+1, right);
            }
        }
     
     
        static class Job{
            int id; int start; int end;
            public Job(int id, int start, int end){
                this.id = id; this.start = start; this.end=end;
            }
        }
    }
# 결과 실행 시간 메모리 Grader output
1 Incorrect 607 ms 28848 KB Output isn't correct
2 Incorrect 610 ms 29088 KB Output isn't correct
3 Incorrect 612 ms 28636 KB Output isn't correct
4 Incorrect 613 ms 28752 KB Output isn't correct
5 Incorrect 623 ms 28744 KB Output isn't correct
6 Incorrect 610 ms 28972 KB Output isn't correct
7 Incorrect 589 ms 29024 KB Output isn't correct
8 Incorrect 581 ms 28984 KB Output isn't correct
9 Incorrect 891 ms 29056 KB Output isn't correct
10 Incorrect 795 ms 28880 KB Output isn't correct
11 Correct 768 ms 28940 KB Output is correct
12 Runtime error 883 ms 41560 KB Memory limit exceeded
13 Execution timed out 1047 ms 56308 KB Time limit exceeded
14 Execution timed out 1065 ms 65536 KB Time limit exceeded
15 Runtime error 722 ms 65536 KB Execution killed with signal 9
16 Runtime error 788 ms 65536 KB Execution killed with signal 9
17 Runtime error 999 ms 65536 KB Execution killed with signal 9
18 Runtime error 924 ms 65536 KB Execution killed with signal 9
19 Runtime error 778 ms 65536 KB Execution killed with signal 9
20 Runtime error 934 ms 65536 KB Execution killed with signal 9