結果

問題 No.94 圏外です。(EASY)
ユーザー yuki2006yuki2006
提出日時 2016-12-18 15:38:49
言語 Java19
(openjdk 21)
結果
AC  
実行時間 244 ms / 5,000 ms
コード長 2,022 bytes
コンパイル時間 3,110 ms
コンパイル使用メモリ 74,048 KB
実行使用メモリ 59,328 KB
最終ジャッジ日時 2023-09-08 15:02:49
合計ジャッジ時間 7,667 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,540 KB
testcase_01 AC 118 ms
56,644 KB
testcase_02 AC 120 ms
55,928 KB
testcase_03 AC 120 ms
55,788 KB
testcase_04 AC 140 ms
55,716 KB
testcase_05 AC 187 ms
56,500 KB
testcase_06 AC 206 ms
56,908 KB
testcase_07 AC 208 ms
56,332 KB
testcase_08 AC 216 ms
59,328 KB
testcase_09 AC 238 ms
58,880 KB
testcase_10 AC 242 ms
59,160 KB
testcase_11 AC 240 ms
58,624 KB
testcase_12 AC 244 ms
58,872 KB
testcase_13 AC 241 ms
58,708 KB
testcase_14 AC 244 ms
58,812 KB
testcase_15 AC 244 ms
58,872 KB
testcase_16 AC 243 ms
59,132 KB
testcase_17 AC 244 ms
58,796 KB
testcase_18 AC 234 ms
59,052 KB
testcase_19 AC 242 ms
59,172 KB
testcase_20 AC 131 ms
55,472 KB
testcase_21 AC 125 ms
55,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static double dist(double A, double B) {
        return Math.sqrt(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 (dist(X[i] - X[j], Y[i] - Y[j]) <= 10) {
                    union.union(i, j);
                }
            }
        }
        double mx = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (union.same(i, j)) {
                    double len = dist(X[i] - X[j], Y[i] - Y[j]);
                    if (mx < len) {
                        mx = len;
                    }
                }
            }
        }
        System.out.println(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]++;
        }
    }

}
0