結果
| 問題 | No.1265 Balloon Survival |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-10-04 11:28:09 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 572 ms / 2,000 ms |
| コード長 | 2,774 bytes |
| 記録 | |
| コンパイル時間 | 2,950 ms |
| コンパイル使用メモリ | 79,280 KB |
| 実行使用メモリ | 70,048 KB |
| 最終ジャッジ日時 | 2024-12-29 17:37:34 |
| 合計ジャッジ時間 | 12,953 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
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();
}
}
tenten