답안 #448359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448359 2021-07-29T20:12:38 Z Vishnu Job Scheduling (CEOI12_jobs) Java 11
컴파일 오류
0 ms 0 KB
import java.io.IOException;
import java.io.File;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;


public static void main(String[] args) throws IOException {
    Scanner myObj = new Scanner(System.in);
    int n = myObj.nextInt();
    int d = myObj.nextInt();
    int m = myObj.nextInt();

    int [][] arr = new int [m][2];
    for (int index = 0; index < m; index++) {
        arr[index][0] = myObj.nextInt();
        arr[index][1] = index + 1;
    }
    Arrays.sort(arr, new Comparator<int[]>() {
        @Override
        public int compare(int[] o1, int[] o2) {
            Integer pos1 = o1[0];
            Integer pos2 = o2[0];

            if (pos1 > pos2) return 1;
            else if (pos1 == pos2) return 0;
            else return -1;
        }
    });

//		for (int index = 0; index < m; index++) {
//			System.out.println("Request: " + arr[index][0]);
//			System.out.println("Index: " + arr[index][1]);
//		}

    int a = 1;
    int b = m;
    int mid;
    while (a != b) {
        mid = (a+b)/2;
        if (works(mid, m, arr, d)) {
            b = mid;
        }
        else {
            a = mid + 1;
        }
    }
    System.out.println(a);


    String output = "";
    int [] mach = new int [a];
    int machine = 0;
    for (int index = 0; index < m; index++) {
        mach[machine] += 1;
        output = output + String.valueOf(arr[index][1]);
        machine++;
        output = output + " ";
        if (machine == a) {
            Arrays.sort(mach);
            machine = 0;
            output = output + "0\n";
        }
    }

    int needFinish = n - (m/a);
    for (int index = 0; index < needFinish; index++) {
        output = output + "0\n";
    }
    System.out.println(output);
}

public static boolean works (int mid, int m, int [][] request_arr, int allowDelay) {		
    int [] mach = new int [mid];
    int delay = 0;
    int machine = 0;
    for (int index = 0; index < m; index++) {
        mach[machine] += 1;
        delay = mach[machine] - request_arr[index][0];
        if (delay > allowDelay) {
            return false;
        }
        machine++;
        if (machine == mid) {
            Arrays.sort(mach);
            machine = 0;
        }
    }
    return true;
}

Compilation message

jobs.java:9: error: class, interface, or enum expected
public static void main(String[] args) throws IOException {
              ^
jobs.java:11: error: class, interface, or enum expected
    int n = myObj.nextInt();
    ^
jobs.java:12: error: class, interface, or enum expected
    int d = myObj.nextInt();
    ^
jobs.java:13: error: class, interface, or enum expected
    int m = myObj.nextInt();
    ^
jobs.java:15: error: class, interface, or enum expected
    int [][] arr = new int [m][2];
    ^
jobs.java:16: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
    ^
jobs.java:16: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
                        ^
jobs.java:16: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
                                   ^
jobs.java:18: error: class, interface, or enum expected
        arr[index][1] = index + 1;
        ^
jobs.java:19: error: class, interface, or enum expected
    }
    ^
jobs.java:22: error: class, interface, or enum expected
        public int compare(int[] o1, int[] o2) {
               ^
jobs.java:24: error: class, interface, or enum expected
            Integer pos2 = o2[0];
            ^
jobs.java:26: error: class, interface, or enum expected
            if (pos1 > pos2) return 1;
            ^
jobs.java:27: error: class, interface, or enum expected
            else if (pos1 == pos2) return 0;
            ^
jobs.java:28: error: class, interface, or enum expected
            else return -1;
            ^
jobs.java:29: error: class, interface, or enum expected
        }
        ^
jobs.java:37: error: class, interface, or enum expected
    int a = 1;
    ^
jobs.java:38: error: class, interface, or enum expected
    int b = m;
    ^
jobs.java:39: error: class, interface, or enum expected
    int mid;
    ^
jobs.java:40: error: class, interface, or enum expected
    while (a != b) {
    ^
jobs.java:42: error: class, interface, or enum expected
        if (works(mid, m, arr, d)) {
        ^
jobs.java:44: error: class, interface, or enum expected
        }
        ^
jobs.java:47: error: class, interface, or enum expected
        }
        ^
jobs.java:52: error: class, interface, or enum expected
    String output = "";
    ^
jobs.java:53: error: class, interface, or enum expected
    int [] mach = new int [a];
    ^
jobs.java:54: error: class, interface, or enum expected
    int machine = 0;
    ^
jobs.java:55: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
    ^
jobs.java:55: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
                        ^
jobs.java:55: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
                                   ^
jobs.java:57: error: class, interface, or enum expected
        output = output + String.valueOf(arr[index][1]);
        ^
jobs.java:58: error: class, interface, or enum expected
        machine++;
        ^
jobs.java:59: error: class, interface, or enum expected
        output = output + " ";
        ^
jobs.java:60: error: class, interface, or enum expected
        if (machine == a) {
        ^
jobs.java:62: error: class, interface, or enum expected
            machine = 0;
            ^
jobs.java:63: error: class, interface, or enum expected
            output = output + "0\n";
            ^
jobs.java:64: error: class, interface, or enum expected
        }
        ^
jobs.java:68: error: class, interface, or enum expected
    for (int index = 0; index < needFinish; index++) {
    ^
jobs.java:68: error: class, interface, or enum expected
    for (int index = 0; index < needFinish; index++) {
                        ^
jobs.java:68: error: class, interface, or enum expected
    for (int index = 0; index < needFinish; index++) {
                                            ^
jobs.java:70: error: class, interface, or enum expected
    }
    ^
jobs.java:72: error: class, interface, or enum expected
}
^
jobs.java:74: error: class, interface, or enum expected
public static boolean works (int mid, int m, int [][] request_arr, int allowDelay) {		
              ^
jobs.java:76: error: class, interface, or enum expected
    int delay = 0;
    ^
jobs.java:77: error: class, interface, or enum expected
    int machine = 0;
    ^
jobs.java:78: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
    ^
jobs.java:78: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
                        ^
jobs.java:78: error: class, interface, or enum expected
    for (int index = 0; index < m; index++) {
                                   ^
jobs.java:80: error: class, interface, or enum expected
        delay = mach[machine] - request_arr[index][0];
        ^
jobs.java:81: error: class, interface, or enum expected
        if (delay > allowDelay) {
        ^
jobs.java:83: error: class, interface, or enum expected
        }
        ^
jobs.java:85: error: class, interface, or enum expected
        if (machine == mid) {
        ^
jobs.java:87: error: class, interface, or enum expected
            machine = 0;
            ^
jobs.java:88: error: class, interface, or enum expected
        }
        ^
jobs.java:91: error: class, interface, or enum expected
}
^
54 errors