結果
問題 | No.94 圏外です。(EASY) |
ユーザー | tenten |
提出日時 | 2021-11-10 11:02:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 107 ms / 5,000 ms |
コード長 | 2,795 bytes |
コンパイル時間 | 1,853 ms |
コンパイル使用メモリ | 77,596 KB |
実行使用メモリ | 52,248 KB |
最終ジャッジ日時 | 2024-04-30 22:12:56 |
合計ジャッジ時間 | 4,593 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
50,376 KB |
testcase_01 | AC | 53 ms
50,440 KB |
testcase_02 | AC | 48 ms
50,372 KB |
testcase_03 | AC | 47 ms
50,332 KB |
testcase_04 | AC | 52 ms
50,352 KB |
testcase_05 | AC | 55 ms
50,716 KB |
testcase_06 | AC | 77 ms
51,564 KB |
testcase_07 | AC | 78 ms
51,808 KB |
testcase_08 | AC | 94 ms
51,756 KB |
testcase_09 | AC | 96 ms
51,928 KB |
testcase_10 | AC | 98 ms
52,076 KB |
testcase_11 | AC | 96 ms
51,860 KB |
testcase_12 | AC | 101 ms
52,072 KB |
testcase_13 | AC | 99 ms
51,884 KB |
testcase_14 | AC | 98 ms
52,196 KB |
testcase_15 | AC | 96 ms
52,028 KB |
testcase_16 | AC | 98 ms
51,880 KB |
testcase_17 | AC | 96 ms
51,936 KB |
testcase_18 | AC | 102 ms
52,248 KB |
testcase_19 | AC | 107 ms
52,052 KB |
testcase_20 | AC | 48 ms
50,120 KB |
testcase_21 | AC | 48 ms
50,032 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); if (n == 0) { System.out.println(1); return; } Point[] poins = new Point[n]; for (int i = 0; i < n; i++) { poins[i] = new Point(sc.nextInt(), sc.nextInt()); } UnionFindTree uft = new UnionFindTree(n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (poins[i].getDistance(poins[j]) <= 100) { uft.unite(i, j); } } } int max = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (uft.same(i, j)) { max = Math.max(max, poins[i].getDistance(poins[j])); } } } System.out.println(Math.sqrt(max) + 2); } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (x == parents[x]) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public void unite(int x, int y) { if (!same(x, y)) { parents[find(y)] = find(x); } } } static class Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } public int getDistance(Point p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }