結果
問題 | No.94 圏外です。(EASY) |
ユーザー | Grenache |
提出日時 | 2016-05-18 20:17:18 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 259 ms / 5,000 ms |
コード長 | 1,771 bytes |
コンパイル時間 | 3,579 ms |
コンパイル使用メモリ | 75,060 KB |
実行使用メモリ | 61,204 KB |
最終ジャッジ日時 | 2023-09-08 14:51:21 |
合計ジャッジ時間 | 9,300 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
55,772 KB |
testcase_01 | AC | 126 ms
55,876 KB |
testcase_02 | AC | 126 ms
56,244 KB |
testcase_03 | AC | 123 ms
56,224 KB |
testcase_04 | AC | 146 ms
56,192 KB |
testcase_05 | AC | 162 ms
57,380 KB |
testcase_06 | AC | 206 ms
56,484 KB |
testcase_07 | AC | 219 ms
59,260 KB |
testcase_08 | AC | 232 ms
59,436 KB |
testcase_09 | AC | 248 ms
59,288 KB |
testcase_10 | AC | 253 ms
59,404 KB |
testcase_11 | AC | 241 ms
59,364 KB |
testcase_12 | AC | 252 ms
59,832 KB |
testcase_13 | AC | 245 ms
57,820 KB |
testcase_14 | AC | 241 ms
59,664 KB |
testcase_15 | AC | 257 ms
59,928 KB |
testcase_16 | AC | 243 ms
59,480 KB |
testcase_17 | AC | 246 ms
59,140 KB |
testcase_18 | AC | 259 ms
61,204 KB |
testcase_19 | AC | 258 ms
60,256 KB |
testcase_20 | AC | 136 ms
55,944 KB |
testcase_21 | AC | 131 ms
55,732 KB |
ソースコード
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; } } }