結果
問題 | No.94 圏外です。(EASY) |
ユーザー | yuki2006 |
提出日時 | 2016-12-18 15:43:09 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 248 ms / 5,000 ms |
コード長 | 2,029 bytes |
コンパイル時間 | 2,154 ms |
コンパイル使用メモリ | 74,468 KB |
実行使用メモリ | 59,488 KB |
最終ジャッジ日時 | 2023-09-08 15:03:05 |
合計ジャッジ時間 | 7,533 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 123 ms
55,544 KB |
testcase_01 | AC | 126 ms
55,644 KB |
testcase_02 | AC | 124 ms
55,864 KB |
testcase_03 | AC | 124 ms
55,804 KB |
testcase_04 | AC | 146 ms
55,856 KB |
testcase_05 | AC | 187 ms
56,524 KB |
testcase_06 | AC | 199 ms
56,892 KB |
testcase_07 | AC | 206 ms
56,644 KB |
testcase_08 | AC | 216 ms
59,488 KB |
testcase_09 | AC | 242 ms
58,436 KB |
testcase_10 | AC | 246 ms
58,432 KB |
testcase_11 | AC | 244 ms
58,868 KB |
testcase_12 | AC | 240 ms
58,600 KB |
testcase_13 | AC | 241 ms
59,024 KB |
testcase_14 | AC | 245 ms
58,924 KB |
testcase_15 | AC | 243 ms
59,308 KB |
testcase_16 | AC | 248 ms
59,216 KB |
testcase_17 | AC | 241 ms
59,020 KB |
testcase_18 | AC | 245 ms
59,208 KB |
testcase_19 | AC | 244 ms
58,800 KB |
testcase_20 | AC | 131 ms
55,760 KB |
testcase_21 | AC | 123 ms
55,760 KB |
ソースコード
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; } 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]++; } } }