結果
| 問題 |
No.1265 Balloon Survival
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2020-10-23 22:29:45 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 719 ms / 2,000 ms |
| コード長 | 1,073 bytes |
| コンパイル時間 | 4,513 ms |
| コンパイル使用メモリ | 80,676 KB |
| 実行使用メモリ | 79,208 KB |
| 最終ジャッジ日時 | 2024-07-21 11:18:43 |
| 合計ジャッジ時間 | 18,888 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] x = new int[n];
int[] y = new int[n];
for (int i = 0; i < n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
sc.close();
PriorityQueue<Obj> que = new PriorityQueue<>((o1, o2) -> Long.compare(o1.d, o2.d));
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
Obj o = new Obj();
o.a = i;
o.b = j;
long dx = x[i] - x[j];
long dy = y[i] - y[j];
o.d = dx * dx + dy * dy;
que.add(o);
}
}
int ans = 0;
boolean[] used = new boolean[n];
while (!que.isEmpty()) {
Obj o = que.poll();
if (used[o.a] || used[o.b]) {
continue;
}
if (o.a != 0 && o.b != 0) {
used[o.a] = true;
used[o.b] = true;
} else {
int c = o.a;
if (c == 0) {
c = o.b;
}
used[c] = true;
ans++;
}
}
System.out.println(ans);
}
static class Obj {
int a, b;
long d;
}
}
ks2m