結果
| 問題 | No.1265 Balloon Survival |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-10-26 09:12:36 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,637 bytes |
| 記録 | |
| コンパイル時間 | 2,783 ms |
| コンパイル使用メモリ | 78,264 KB |
| 実行使用メモリ | 69,792 KB |
| 最終ジャッジ日時 | 2024-07-21 21:16:04 |
| 合計ジャッジ時間 | 17,752 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 31 WA * 1 |
ソースコード
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;
double dist;
public Unit(int left, int right, int x, int y) {
this.left = left;
this.right = right;
dist = Math.pow(x, 2) + Math.pow(y, 2);
}
public int compareTo(Unit another) {
if (dist == another.dist) {
return 0;
} else if (dist < another.dist) {
return -1;
} else {
return 1;
}
}
}
}
tenten