結果

問題 No.168 ものさし
ユーザー task4233task4233
提出日時 2019-01-01 21:04:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,330 bytes
コンパイル時間 1,353 ms
コンパイル使用メモリ 167,956 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-25 15:17:18
合計ジャッジ時間 2,511 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 16 ms
6,940 KB
testcase_12 AC 48 ms
8,704 KB
testcase_13 AC 67 ms
11,136 KB
testcase_14 AC 67 ms
11,008 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 42 ms
10,752 KB
testcase_20 AC 44 ms
11,136 KB
testcase_21 AC 44 ms
11,008 KB
testcase_22 AC 45 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct UnionFind {
  vector< int > par;
  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n = 1) {
    par.resize(n);
    for(int i = 0; i < n; i++)
      par[i] = -1;
  }
  
  int root(int n) {
    if (par[n] < 0) return n;
    return par[n] = root(par[n]);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;

    return true;
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  int n;
  cin >> n;
  vector< int64_t > x(n), y(n); 
  for (int i=0; i<n; ++i) cin >> x[i] >> y[i];
  
  vector< vector< int64_t > > d(n, vector< int64_t >(n, 0));
  for (int i=0; i<n; ++i) {
    for (int j=0; j<n; ++j) {
      d[i][j] = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
    }
  }

  
  auto check = [&](int64_t k) {
    UnionFind uf(n+1);
    for (int i=0; i<n; ++i) {
      for (int j=0; j<n; ++j) {
        if (d[i][j] <= k*k*100) uf.merge(i, j); 
      }
    }
    return uf.issame(0, n-1);    
  };
  
  // 範囲は[ng, ok). 
  int64_t ng = 0LL, ok = 1e9+1;
  while (ok-ng > 1LL) {
    int64_t mid = (ok+ng)/2;
    (check(mid) ? ok : ng) = mid;
  }
  int64_t ans = ok * 10LL;
  cout << ans << endl;

  return 0;
}
  
0