結果
| 問題 | No.94 圏外です。(EASY) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-18 17:03:14 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 260 ms / 5,000 ms |
| コード長 | 2,126 bytes |
| 記録 | |
| コンパイル時間 | 2,322 ms |
| コンパイル使用メモリ | 77,668 KB |
| 実行使用メモリ | 44,024 KB |
| 最終ジャッジ日時 | 2024-06-26 08:07:54 |
| 合計ジャッジ時間 | 8,040 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
import java.util.Scanner;
public class Main {
public static int distNotSqrt(int A, int B) {
return A * A + B * B;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] X = new int[N];
int[] Y = new int[N];
if (N == 0) {
System.out.println(1);
return;
}
for (int i = 0; i < N; i++) {
X[i] = scanner.nextInt();
Y[i] = scanner.nextInt();
}
UnionFind union = new UnionFind(N);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (distNotSqrt(X[i] - X[j], Y[i] - Y[j]) <= 100) {
union.union(i, j);
}
}
}
int mx = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (union.same(i, j)) {
int len = distNotSqrt(X[i] - X[j], Y[i] - Y[j]);
if (mx < len) {
mx = len;
}
}
}
}
System.out.println(Math.sqrt(mx) + 2);
}
}
class UnionFind {
int[] parent;
int[] rank;
public UnionFind(int N) {
parent = new int[N];
rank = new int[N];
for (int i = 0; i < N; i++) {
parent[i] = i;
}
}
public int find(int A) {
if (parent[A] == A) {
return A;
}
parent[A] = find(parent[A]);
return parent[A];
}
public boolean same(int A, int B) {
return find(A) == find(B);
}
public boolean union(int A, int B) {
int Aroot = find(A);
int Broot = find(B);
if (Aroot == Broot) {
return false;
}
if (rank[Aroot] > rank[Broot]) {
parent[Broot] = Aroot;
} else if (rank[Aroot] < rank[Broot]) {
parent[Aroot] = Broot;
} else {
parent[Aroot] = Broot;
rank[Broot]++;
}
return true;
}
}