結果

問題 No.168 ものさし
ユーザー takeya_okinotakeya_okino
提出日時 2019-07-21 13:46:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 716 ms / 2,000 ms
コード長 1,581 bytes
コンパイル時間 4,489 ms
コンパイル使用メモリ 73,208 KB
実行使用メモリ 59,728 KB
最終ジャッジ日時 2023-09-02 21:56:16
合計ジャッジ時間 12,262 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 307 ms
56,888 KB
testcase_01 AC 131 ms
55,568 KB
testcase_02 AC 130 ms
55,540 KB
testcase_03 AC 129 ms
55,740 KB
testcase_04 AC 128 ms
55,676 KB
testcase_05 AC 127 ms
55,688 KB
testcase_06 AC 130 ms
56,364 KB
testcase_07 AC 127 ms
55,720 KB
testcase_08 AC 129 ms
55,336 KB
testcase_09 AC 183 ms
56,524 KB
testcase_10 AC 208 ms
56,964 KB
testcase_11 AC 312 ms
57,256 KB
testcase_12 AC 386 ms
59,728 KB
testcase_13 AC 420 ms
59,344 KB
testcase_14 AC 431 ms
59,644 KB
testcase_15 AC 132 ms
55,764 KB
testcase_16 AC 164 ms
55,868 KB
testcase_17 AC 202 ms
56,588 KB
testcase_18 AC 229 ms
56,152 KB
testcase_19 AC 716 ms
59,568 KB
testcase_20 AC 408 ms
58,836 KB
testcase_21 AC 408 ms
59,168 KB
testcase_22 AC 406 ms
59,524 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];
    for(int i = 0; i < n; i++) {
      x[i] = sc.nextLong();
      y[i] = sc.nextLong();
    }
    init(n);
    long l = 0;
    long r = (long)Math.pow(10, 10);
    long ans = 0;
    while(l < r) {
      long med = (l + r) / 2;
      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])) <= med * med) unite(i, j);
        }
      }
      if(same(0, n - 1)) {
        ans = med;
        r = med;
      } else {
        l = med + 1;
      }
      init(n);
    }
    for(int i = 0; i < 10; i++) {
      if(ans % 10 == 0) break;
      ans++; 
    }
    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