結果

問題 No.1265 Balloon Survival
ユーザー tentententen
提出日時 2020-10-26 09:15:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 718 ms / 2,000 ms
コード長 1,619 bytes
コンパイル時間 3,312 ms
コンパイル使用メモリ 74,524 KB
実行使用メモリ 82,716 KB
最終ジャッジ日時 2023-09-29 02:29:22
合計ジャッジ時間 16,352 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,400 KB
testcase_01 AC 129 ms
55,612 KB
testcase_02 AC 128 ms
56,152 KB
testcase_03 AC 131 ms
55,856 KB
testcase_04 AC 130 ms
55,856 KB
testcase_05 AC 134 ms
55,704 KB
testcase_06 AC 134 ms
55,920 KB
testcase_07 AC 133 ms
56,068 KB
testcase_08 AC 131 ms
53,996 KB
testcase_09 AC 130 ms
55,832 KB
testcase_10 AC 130 ms
56,000 KB
testcase_11 AC 133 ms
55,964 KB
testcase_12 AC 135 ms
56,400 KB
testcase_13 AC 131 ms
56,064 KB
testcase_14 AC 293 ms
60,036 KB
testcase_15 AC 284 ms
58,528 KB
testcase_16 AC 220 ms
58,208 KB
testcase_17 AC 491 ms
66,020 KB
testcase_18 AC 239 ms
59,156 KB
testcase_19 AC 224 ms
57,772 KB
testcase_20 AC 292 ms
59,408 KB
testcase_21 AC 343 ms
63,552 KB
testcase_22 AC 305 ms
59,120 KB
testcase_23 AC 313 ms
59,044 KB
testcase_24 AC 688 ms
80,920 KB
testcase_25 AC 707 ms
81,024 KB
testcase_26 AC 696 ms
80,516 KB
testcase_27 AC 718 ms
80,508 KB
testcase_28 AC 715 ms
80,976 KB
testcase_29 AC 717 ms
80,824 KB
testcase_30 AC 701 ms
80,476 KB
testcase_31 AC 692 ms
82,716 KB
testcase_32 AC 718 ms
80,584 KB
testcase_33 AC 712 ms
80,692 KB
testcase_34 AC 141 ms
55,764 KB
testcase_35 AC 130 ms
55,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] xs = new int[n];
        int[] ys = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
            ys[i] = sc.nextInt();
        }
        PriorityQueue<Unit> queue = new PriorityQueue<>();
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                queue.add(new Unit(i, j, xs[i] - xs[j], ys[i] - ys[j]));
            }
        }
        int count = 0;
        boolean[] used = new boolean[n];
        while (queue.size() > 0) {
            Unit u = queue.poll();
            if (used[u.left] || used[u.right]) {
                continue;
            }
            if (u.left == 0) {
                used[u.right] = true;
                count++;
            } else {
                used[u.left] = true;
                used[u.right] = true;
            }
        }
        System.out.println(count);
    }
    
    static class Unit implements Comparable<Unit> {
        int left;
        int right;
        long dist;
        
        public Unit(int left, int right, long x, long y) {
            this.left = left;
            this.right = right;
            dist = x * x + y * y;
        }
        
        public int compareTo(Unit another) {
            if (dist == another.dist) {
                return 0;
            } else if (dist < another.dist) {
                return -1;
            } else {
                return 1;
            }
        }
    }
}
0