結果
問題 | No.94 圏外です。(EASY) |
ユーザー | tenten |
提出日時 | 2020-10-27 13:46:52 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,361 bytes |
コンパイル時間 | 2,851 ms |
コンパイル使用メモリ | 76,196 KB |
実行使用メモリ | 60,792 KB |
最終ジャッジ日時 | 2023-09-29 03:16:31 |
合計ジャッジ時間 | 9,000 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 132 ms
55,672 KB |
testcase_01 | AC | 132 ms
55,916 KB |
testcase_02 | AC | 131 ms
55,620 KB |
testcase_03 | WA | - |
testcase_04 | AC | 157 ms
55,824 KB |
testcase_05 | AC | 186 ms
56,204 KB |
testcase_06 | AC | 204 ms
56,296 KB |
testcase_07 | AC | 218 ms
57,020 KB |
testcase_08 | AC | 225 ms
59,224 KB |
testcase_09 | AC | 259 ms
59,672 KB |
testcase_10 | AC | 248 ms
60,792 KB |
testcase_11 | AC | 251 ms
59,144 KB |
testcase_12 | AC | 247 ms
59,032 KB |
testcase_13 | AC | 254 ms
59,620 KB |
testcase_14 | AC | 249 ms
58,720 KB |
testcase_15 | AC | 256 ms
59,728 KB |
testcase_16 | AC | 244 ms
59,008 KB |
testcase_17 | AC | 252 ms
59,048 KB |
testcase_18 | AC | 244 ms
59,208 KB |
testcase_19 | AC | 267 ms
59,448 KB |
testcase_20 | AC | 135 ms
55,764 KB |
testcase_21 | AC | 131 ms
55,700 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Point[] points = new Point[n]; for (int i = 0; i < n; i++) { points[i] = new Point(sc.nextInt(), sc.nextInt()); } UnionFindTree uft = new UnionFindTree(n); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (uft.same(i, j)) { continue; } if (points[i].getDist(points[j]) <= 100) { uft.unite(i, j); } } } HashMap<Integer, ArrayList<Point>> map = new HashMap<>(); for (int i = 0; i < n; i++) { int key = uft.find(i); if (!map.containsKey(key)) { map.put(key, new ArrayList<>()); } map.get(key).add(points[i]); } int max = 0; for (ArrayList<Point> list : map.values()) { for (int i = 0; i < list.size() - 1; i++) { for (int j = i + 1; j < list.size(); j++) { max = Math.max(max, list.get(i).getDist(list.get(j))); } } } System.out.println(Math.sqrt(max) + 2); } static class Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } public int getDist(Point another) { return (x - another.x) * (x - another.x) + (y - another.y) * (y - another.y); } } 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(x)] = find(y); } } } }