Submission #1147943

#TimeUsernameProblemLanguageResultExecution timeMemory
1147943sossa_abelCoin Collecting (JOI19_ho_t4)Java
Compilation error
0 ms0 KiB
import java.io.*; import java.util.*; public class Main { static class State { int x, y; int distance; State(int x, int y, int distance) { this.x = x; this.y = y; this.distance = distance; } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); List<int[]> coins = new ArrayList<>(); for (int i = 0; i < 2 * n; i++) { String[] parts = br.readLine().split(" "); int x = Integer.parseInt(parts[0]); int y = Integer.parseInt(parts[1]); coins.add(new int[]{x, y}); } long totalMoves = 0; boolean[] used = new boolean[2 * n]; for (int x = 1; x <= n; x++) { for (int y = 1; y <= 2; y++) { int minMoves = Integer.MAX_VALUE; int bestCoin = -1; for (int i = 0; i < 2 * n; i++) { if (!used[i]) { int moves = Math.abs(coins.get(i)[0] - x) + Math.abs(coins.get(i)[1] - y); if (moves < minMoves) { minMoves = moves; bestCoin = i; } } } if (bestCoin != -1) { used[bestCoin] = true; totalMoves += minMoves; } } } System.out.println(totalMoves); } }

Compilation message (stderr)

joi2019_ho_t4.java:4: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
1 error

=======