結果
問題 | No.1265 Balloon Survival |
ユーザー | tenten |
提出日時 | 2022-08-04 16:52:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 535 ms / 2,000 ms |
コード長 | 2,644 bytes |
コンパイル時間 | 2,379 ms |
コンパイル使用メモリ | 79,088 KB |
実行使用メモリ | 69,704 KB |
最終ジャッジ日時 | 2024-09-14 13:32:22 |
合計ジャッジ時間 | 11,741 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
36,948 KB |
testcase_01 | AC | 52 ms
36,836 KB |
testcase_02 | AC | 52 ms
36,968 KB |
testcase_03 | AC | 53 ms
36,956 KB |
testcase_04 | AC | 52 ms
37,144 KB |
testcase_05 | AC | 52 ms
36,456 KB |
testcase_06 | AC | 55 ms
36,816 KB |
testcase_07 | AC | 54 ms
36,716 KB |
testcase_08 | AC | 54 ms
36,948 KB |
testcase_09 | AC | 52 ms
36,992 KB |
testcase_10 | AC | 53 ms
36,916 KB |
testcase_11 | AC | 54 ms
37,000 KB |
testcase_12 | AC | 55 ms
37,144 KB |
testcase_13 | AC | 54 ms
36,688 KB |
testcase_14 | AC | 163 ms
41,752 KB |
testcase_15 | AC | 148 ms
41,572 KB |
testcase_16 | AC | 98 ms
39,028 KB |
testcase_17 | AC | 349 ms
56,212 KB |
testcase_18 | AC | 125 ms
39,752 KB |
testcase_19 | AC | 110 ms
39,092 KB |
testcase_20 | AC | 160 ms
42,520 KB |
testcase_21 | AC | 211 ms
47,480 KB |
testcase_22 | AC | 182 ms
46,224 KB |
testcase_23 | AC | 190 ms
46,424 KB |
testcase_24 | AC | 511 ms
69,344 KB |
testcase_25 | AC | 515 ms
69,356 KB |
testcase_26 | AC | 488 ms
68,828 KB |
testcase_27 | AC | 530 ms
69,448 KB |
testcase_28 | AC | 525 ms
69,704 KB |
testcase_29 | AC | 535 ms
69,664 KB |
testcase_30 | AC | 529 ms
69,404 KB |
testcase_31 | AC | 526 ms
69,428 KB |
testcase_32 | AC | 532 ms
69,540 KB |
testcase_33 | AC | 526 ms
69,512 KB |
testcase_34 | AC | 56 ms
37,144 KB |
testcase_35 | AC | 53 ms
36,588 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(); Point[] points = new Point[n]; for (int i = 0; i < n; i++) { points[i] = new Point(sc.nextInt(), sc.nextInt()); } PriorityQueue<Path> queue = new PriorityQueue<>(); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { queue.add(new Path(i, j, points[i].getDistance(points[j]))); } } HashSet<Integer> removed = new HashSet<>(); int count = 0; while (queue.size() > 0) { Path p = queue.poll(); if (removed.contains(p.left) || removed.contains(p.right)) { continue; } if (p.left == 0) { removed.add(p.right); count++; continue; } removed.add(p.left); removed.add(p.right); } System.out.println(count); } static class Path implements Comparable<Path> { int left; int right; long value; public Path(int left, int right, long value) { this.left = left; this.right = right; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return -1; } else { return 1; } } } static class Point { long x; long y; public Point(long x, long y) { this.x = x; this.y = y; } public long getDistance(Point p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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(); } }