結果

問題 No.1265 Balloon Survival
ユーザー tentententen
提出日時 2022-10-04 11:28:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 592 ms / 2,000 ms
コード長 2,774 bytes
コンパイル時間 3,348 ms
コンパイル使用メモリ 78,100 KB
実行使用メモリ 79,152 KB
最終ジャッジ日時 2024-06-09 10:20:58
合計ジャッジ時間 12,594 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,068 KB
testcase_01 AC 54 ms
37,160 KB
testcase_02 AC 54 ms
37,208 KB
testcase_03 AC 54 ms
36,832 KB
testcase_04 AC 54 ms
37,136 KB
testcase_05 AC 54 ms
36,564 KB
testcase_06 AC 56 ms
36,692 KB
testcase_07 AC 55 ms
37,068 KB
testcase_08 AC 54 ms
36,972 KB
testcase_09 AC 54 ms
36,960 KB
testcase_10 AC 54 ms
36,936 KB
testcase_11 AC 54 ms
37,004 KB
testcase_12 AC 53 ms
36,656 KB
testcase_13 AC 53 ms
37,092 KB
testcase_14 AC 174 ms
42,508 KB
testcase_15 AC 149 ms
41,940 KB
testcase_16 AC 112 ms
38,964 KB
testcase_17 AC 345 ms
54,348 KB
testcase_18 AC 124 ms
39,888 KB
testcase_19 AC 117 ms
39,696 KB
testcase_20 AC 177 ms
43,068 KB
testcase_21 AC 231 ms
46,944 KB
testcase_22 AC 205 ms
47,108 KB
testcase_23 AC 214 ms
47,092 KB
testcase_24 AC 568 ms
79,152 KB
testcase_25 AC 583 ms
70,116 KB
testcase_26 AC 592 ms
69,936 KB
testcase_27 AC 558 ms
70,144 KB
testcase_28 AC 557 ms
69,744 KB
testcase_29 AC 567 ms
69,980 KB
testcase_30 AC 539 ms
69,652 KB
testcase_31 AC 541 ms
69,748 KB
testcase_32 AC 561 ms
69,708 KB
testcase_33 AC 569 ms
70,072 KB
testcase_34 AC 56 ms
36,676 KB
testcase_35 AC 54 ms
37,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        Baloon[] baloons = new Baloon[n];
        PriorityQueue<Distance> distances = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            baloons[i] = new Baloon(sc.nextInt(), sc.nextInt());
            for (int j = 0; j < i; j++) {
                distances.add(new Distance(j, i, baloons[i].getDistance(baloons[j])));
            }
        }
        int count = 0;
        HashSet<Integer> displaced = new HashSet<>();
        while (distances.size() > 0) {
            Distance x = distances.poll();
            if (x.left == 0) {
                if (!displaced.contains(x.right)) {
                    count++;
                    displaced.add(x.right);
                }
            } else if (!displaced.contains(x.left) && !displaced.contains(x.right)) {
                displaced.add(x.left);
                displaced.add(x.right);
            }
        }
        System.out.println(count);
    }
    
    static class Distance implements Comparable<Distance> {
        int left;
        int right;
        long length;
        
        public Distance(int left, int right, long length) {
            this.left = left;
            this.right = right;
            this.length = length;
        }
        
        public int compareTo(Distance another) {
            if (length == another.length) {
                return 0;
            } else if (length < another.length) {
                return -1;
            } else {
                return 1;
            }
        }
    }
    
    static class Baloon {
        long x;
        long y;
        
        public Baloon(long x, long y) {
            this.x = x;
            this.y = y;
        }
        
        public long getDistance(Baloon another) {
            return (x - another.x) * (x - another.x) + (y - another.y) * (y - another.y);
        }
    }
}
    
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0