結果
問題 | No.1265 Balloon Survival |
ユーザー | tenten |
提出日時 | 2022-10-04 11:28:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 631 ms / 2,000 ms |
コード長 | 2,774 bytes |
コンパイル時間 | 2,636 ms |
コンパイル使用メモリ | 75,752 KB |
実行使用メモリ | 80,812 KB |
最終ジャッジ日時 | 2023-08-28 15:09:58 |
合計ジャッジ時間 | 13,196 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,996 KB |
testcase_01 | AC | 45 ms
49,568 KB |
testcase_02 | AC | 45 ms
49,428 KB |
testcase_03 | AC | 46 ms
49,504 KB |
testcase_04 | AC | 47 ms
49,548 KB |
testcase_05 | AC | 47 ms
49,484 KB |
testcase_06 | AC | 48 ms
49,876 KB |
testcase_07 | AC | 47 ms
49,580 KB |
testcase_08 | AC | 46 ms
49,420 KB |
testcase_09 | AC | 45 ms
49,456 KB |
testcase_10 | AC | 46 ms
49,416 KB |
testcase_11 | AC | 47 ms
49,552 KB |
testcase_12 | AC | 48 ms
49,540 KB |
testcase_13 | AC | 46 ms
49,364 KB |
testcase_14 | AC | 172 ms
55,192 KB |
testcase_15 | AC | 153 ms
38,468 KB |
testcase_16 | AC | 101 ms
36,176 KB |
testcase_17 | AC | 402 ms
54,100 KB |
testcase_18 | AC | 103 ms
36,624 KB |
testcase_19 | AC | 102 ms
36,216 KB |
testcase_20 | AC | 168 ms
39,648 KB |
testcase_21 | AC | 227 ms
44,040 KB |
testcase_22 | AC | 188 ms
43,108 KB |
testcase_23 | AC | 207 ms
43,300 KB |
testcase_24 | AC | 631 ms
67,632 KB |
testcase_25 | AC | 629 ms
80,812 KB |
testcase_26 | AC | 611 ms
67,568 KB |
testcase_27 | AC | 612 ms
80,792 KB |
testcase_28 | AC | 599 ms
67,216 KB |
testcase_29 | AC | 606 ms
80,436 KB |
testcase_30 | AC | 583 ms
66,956 KB |
testcase_31 | AC | 620 ms
80,732 KB |
testcase_32 | AC | 616 ms
67,340 KB |
testcase_33 | AC | 618 ms
80,208 KB |
testcase_34 | AC | 44 ms
33,524 KB |
testcase_35 | AC | 43 ms
33,872 KB |
ソースコード
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(); } }