結果

問題 No.94 圏外です。(EASY)
ユーザー takeya_okinotakeya_okino
提出日時 2019-07-21 14:56:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,501 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 73,796 KB
実行使用メモリ 59,236 KB
最終ジャッジ日時 2023-09-03 19:36:53
合計ジャッジ時間 8,074 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
56,096 KB
testcase_01 AC 105 ms
55,456 KB
testcase_02 AC 105 ms
55,836 KB
testcase_03 WA -
testcase_04 AC 122 ms
55,708 KB
testcase_05 AC 140 ms
56,188 KB
testcase_06 AC 174 ms
56,468 KB
testcase_07 AC 188 ms
55,588 KB
testcase_08 AC 215 ms
59,236 KB
testcase_09 AC 203 ms
59,228 KB
testcase_10 AC 200 ms
58,604 KB
testcase_11 AC 209 ms
58,964 KB
testcase_12 AC 210 ms
58,952 KB
testcase_13 AC 219 ms
59,132 KB
testcase_14 AC 212 ms
59,068 KB
testcase_15 AC 215 ms
58,832 KB
testcase_16 AC 210 ms
59,092 KB
testcase_17 AC 211 ms
58,768 KB
testcase_18 AC 220 ms
58,740 KB
testcase_19 AC 232 ms
58,872 KB
testcase_20 AC 121 ms
55,648 KB
testcase_21 AC 118 ms
55,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  static int[] par;
  static int[] rank;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    par = new int[n];
    rank = new int[n];
    long[] x = new long[n];
    long[] y = new long[n];
    init(n);
    for(int i = 0; i < n; i++) {
      x[i] = sc.nextLong();
      y[i] = sc.nextLong();
    }
    for(int i = 0; i < n - 1; i++) {
      for(int j = i + 1; j < n; j++) {
        if(((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) <= 100) unite(i, j);
      }
    }
    double ans = 0;
    for(int i = 0; i < n - 1; i++) {
      for(int j = i + 1; j < n; j++) {
        if(same(i, j)) ans = Math.max(ans, Math.sqrt(((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])))); 
      }
    }
    ans += 2;
    if(n == 0) ans = 0;
    System.out.println(ans);
  }
  static void init(int m) {
      for(int i = 0; i < m; i++) {
        par[i] = i;
        rank[i] = 0;
      }
    }
  static int find(int x) {
      if(par[x] == x) {
        return x;
      } else {
        return par[x] = find(par[x]);
      }
    }
  static void unite(int x, int y) {
      x = find(x);
      y = find(y);
      if(x != y) {
        if(rank[x] < rank[y]) {
          par[x] = y;
        } else {
          par[y] = x;
          if(rank[x] == rank[y]) {
            rank[x]++;
          }
        }
      }
    }
  static boolean same(int x, int y) {
      return find(x) == find(y);
    }
}
0