結果

問題 No.94 圏外です。(EASY)
ユーザー tentententen
提出日時 2020-10-27 13:47:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 2,448 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 76,516 KB
実行使用メモリ 43,384 KB
最終ジャッジ日時 2023-09-29 03:16:40
合計ジャッジ時間 8,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
39,540 KB
testcase_01 AC 125 ms
39,452 KB
testcase_02 AC 124 ms
39,464 KB
testcase_03 AC 122 ms
39,400 KB
testcase_04 AC 148 ms
40,240 KB
testcase_05 AC 189 ms
40,596 KB
testcase_06 AC 200 ms
40,348 KB
testcase_07 AC 212 ms
41,556 KB
testcase_08 AC 225 ms
41,888 KB
testcase_09 AC 249 ms
42,436 KB
testcase_10 AC 259 ms
43,144 KB
testcase_11 AC 243 ms
42,076 KB
testcase_12 AC 259 ms
43,384 KB
testcase_13 AC 256 ms
41,832 KB
testcase_14 AC 264 ms
42,276 KB
testcase_15 AC 256 ms
42,032 KB
testcase_16 AC 255 ms
41,984 KB
testcase_17 AC 247 ms
41,844 KB
testcase_18 AC 251 ms
41,832 KB
testcase_19 AC 270 ms
41,984 KB
testcase_20 AC 131 ms
39,456 KB
testcase_21 AC 124 ms
39,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
            }
        }
    }
}
0