結果
問題 | No.94 圏外です。(EASY) |
ユーザー | yuki2006 |
提出日時 | 2016-12-18 15:36:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 258 ms / 5,000 ms |
コード長 | 1,934 bytes |
コンパイル時間 | 2,119 ms |
コンパイル使用メモリ | 73,876 KB |
実行使用メモリ | 59,708 KB |
最終ジャッジ日時 | 2023-09-08 15:03:41 |
合計ジャッジ時間 | 7,546 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 119 ms
55,724 KB |
testcase_01 | AC | 117 ms
55,808 KB |
testcase_02 | AC | 120 ms
55,948 KB |
testcase_03 | AC | 118 ms
55,492 KB |
testcase_04 | AC | 154 ms
55,756 KB |
testcase_05 | AC | 193 ms
56,268 KB |
testcase_06 | AC | 204 ms
57,368 KB |
testcase_07 | AC | 215 ms
57,368 KB |
testcase_08 | AC | 246 ms
59,324 KB |
testcase_09 | AC | 248 ms
58,764 KB |
testcase_10 | AC | 251 ms
59,024 KB |
testcase_11 | AC | 250 ms
59,184 KB |
testcase_12 | AC | 254 ms
59,412 KB |
testcase_13 | AC | 258 ms
58,556 KB |
testcase_14 | AC | 254 ms
59,708 KB |
testcase_15 | AC | 254 ms
58,964 KB |
testcase_16 | AC | 254 ms
59,276 KB |
testcase_17 | AC | 250 ms
58,952 KB |
testcase_18 | AC | 254 ms
59,224 KB |
testcase_19 | AC | 251 ms
59,076 KB |
testcase_20 | AC | 128 ms
55,796 KB |
testcase_21 | AC | 120 ms
55,748 KB |
ソースコード
import java.util.Scanner; public class Main { 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 (Math.hypot(X[i] - X[j], Y[i] - Y[j]) <= 10) { union.union(i, j); } } } double mx = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (union.same(i, j)) { double len = Math.hypot(X[i] - X[j], Y[i] - Y[j]); if (mx < len) { mx = len; } } } } System.out.println(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; } return find(parent[A]); } public boolean same(int A, int B) { return find(A) == find(B); } public void union(int A, int B) { int Aroot = find(A); int Broot = find(B); if (rank[Aroot] > rank[Broot]) { parent[Broot] = Aroot; } else if (rank[Aroot] < rank[Broot]) { parent[Aroot] = Broot; } else if (Aroot != Broot) { parent[Aroot] = Broot; rank[Broot]++; } } }