제출 #1148053

#제출 시각아이디문제언어결과실행 시간메모리
1148053pablo_floresCoin Collecting (JOI19_ho_t4)Java
컴파일 에러
0 ms0 KiB
import java.util.*;

public class Joi2019HoT4 {

    static final int MAXN = 100010;
    static int n;
    static int[][] mat = new int[MAXN][3]; 
    static long ans = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        readInput(scanner);

        calculateBalance();

        System.out.println(ans);

        scanner.close();
    }

    private static void readInput(Scanner scanner) {
        n = scanner.nextInt();

        for (int i = 1; i <= 2 * n; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();

            processPoint(x, y);
        }
    }
    
    private static void processPoint(int x, int y) {
        if (x < 1) {
            if (y >= 2) {
                mat[1][2]++;
                ans += Math.abs(x - 1) + Math.abs(y - 2);
            } else {
                mat[1][1]++;
                ans += Math.abs(x - 1) + Math.abs(y - 1);
            }
        } else if (x >= 1 && x <= n) {
            if (y >= 2) {
                mat[x][2]++;
                ans += Math.abs(y - 2);
            } else {
                mat[x][1]++;
                ans += Math.abs(y - 1);
            }
        } else if (x > n) {
            if (y >= 2) {
                mat[n][2]++;
                ans += Math.abs(x - n) + Math.abs(y - 2);
            } else {
                mat[n][1]++;
                ans += Math.abs(x - n) + Math.abs(y - 1);
            }
        }
    }

    private static void calculateBalance() {
        long num1 = 0, num2 = 0; 

        for (int i = 1; i <= n; i++) {
            num1 += (mat[i][1] - 1);
            num2 += (mat[i][2] - 1);

            balanceColumns();

            ans += Math.abs(num1) + Math.abs(num2);
        }
    }

    private static void balanceColumns() {
        while (num1 > 0 && num2 < 0) {
            num1--;
            num2++;
            ans++;
        }
        while (num1 < 0 && num2 > 0) {
            num1++;
            num2--;
            ans++;
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

joi2019_ho_t4.java:3: error: class Joi2019HoT4 is public, should be declared in a file named Joi2019HoT4.java
public class Joi2019HoT4 {
       ^
joi2019_ho_t4.java:75: error: cannot find symbol
        while (num1 > 0 && num2 < 0) {
               ^
  symbol:   variable num1
  location: class Joi2019HoT4
joi2019_ho_t4.java:75: error: cannot find symbol
        while (num1 > 0 && num2 < 0) {
                           ^
  symbol:   variable num2
  location: class Joi2019HoT4
joi2019_ho_t4.java:76: error: cannot find symbol
            num1--;
            ^
  symbol:   variable num1
  location: class Joi2019HoT4
joi2019_ho_t4.java:77: error: cannot find symbol
            num2++;
            ^
  symbol:   variable num2
  location: class Joi2019HoT4
joi2019_ho_t4.java:80: error: cannot find symbol
        while (num1 < 0 && num2 > 0) {
               ^
  symbol:   variable num1
  location: class Joi2019HoT4
joi2019_ho_t4.java:80: error: cannot find symbol
        while (num1 < 0 && num2 > 0) {
                           ^
  symbol:   variable num2
  location: class Joi2019HoT4
joi2019_ho_t4.java:81: error: cannot find symbol
            num1++;
            ^
  symbol:   variable num1
  location: class Joi2019HoT4
joi2019_ho_t4.java:82: error: cannot find symbol
            num2--;
            ^
  symbol:   variable num2
  location: class Joi2019HoT4
9 errors

=======