結果
| 問題 |
No.1265 Balloon Survival
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-10-26 09:15:19 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 652 ms / 2,000 ms |
| コード長 | 1,619 bytes |
| コンパイル時間 | 2,225 ms |
| コンパイル使用メモリ | 78,364 KB |
| 実行使用メモリ | 79,140 KB |
| 最終ジャッジ日時 | 2024-07-21 21:16:29 |
| 合計ジャッジ時間 | 14,912 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
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;
}
}
}
}
tenten