結果
| 問題 | No.94 圏外です。(EASY) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-05-18 20:17:18 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 276 ms / 5,000 ms |
| コード長 | 1,771 bytes |
| 記録 | |
| コンパイル時間 | 3,745 ms |
| コンパイル使用メモリ | 77,996 KB |
| 実行使用メモリ | 47,224 KB |
| 最終ジャッジ日時 | 2024-06-26 07:56:06 |
| 合計ジャッジ時間 | 9,614 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
import java.util.*;
public class Main_yukicoder94 {
public static void main(String[] args) {
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();
}
UnionFind uf = new UnionFind(n);
int[][] dis = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
dis[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
if (dis[i][j] <= 100) {
uf.union(i, j);
}
}
}
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (uf.same(i, j)) {
max = Math.max(max, dis[i][j]);
}
}
}
if (n == 0) {
System.out.println(1);
} else {
System.out.printf("%.7f\n", Math.sqrt(max) + 2);
}
sc.close();
}
@SuppressWarnings("unused")
private static class UnionFind {
int[] parent;
int[] rank;
UnionFind(int n) {
parent = new int[n];
rank = new int[n];
for (int i = 0; i < n; i++) {
parent[i] = i;
rank[i] = 0;
}
}
int find(int x) {
if (parent[x] == x) {
return x;
} else {
return parent[x] = find(parent[x]);
}
}
boolean same(int x, int y) {
return find(x) == find(y);
}
void union(int x, int y) {
x = find(x);
y = find(y);
if (x != y) {
if (rank[x] > rank[y]) {
parent[y] = x;
} else {
parent[x] = y;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
return;
}
// 異なる集合の数
int count() {
int ret = 0;
for (int i = 0; i < parent.length; i++) {
if (find(i) == i) {
ret++;
}
}
return ret;
}
}
}