結果
問題 | No.94 圏外です。(EASY) |
ユーザー |
![]() |
提出日時 | 2020-10-27 13:47:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 262 ms / 5,000 ms |
コード長 | 2,448 bytes |
コンパイル時間 | 3,111 ms |
コンパイル使用メモリ | 79,536 KB |
実行使用メモリ | 44,456 KB |
最終ジャッジ日時 | 2024-07-21 21:55:25 |
合計ジャッジ時間 | 7,203 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n == 0) { System.out.println(1); return; } 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); } } } }