結果

問題 No.168 ものさし
ユーザー ありあり
提出日時 2023-02-21 09:58:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 940 ms
コンパイル使用メモリ 91,604 KB
実行使用メモリ 11,088 KB
最終ジャッジ日時 2023-09-29 04:15:25
合計ジャッジ時間 2,864 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,132 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 23 ms
4,980 KB
testcase_12 AC 72 ms
8,584 KB
testcase_13 AC 103 ms
10,892 KB
testcase_14 AC 102 ms
10,900 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 53 ms
10,820 KB
testcase_20 AC 55 ms
11,084 KB
testcase_21 AC 55 ms
11,076 KB
testcase_22 AC 56 ms
11,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
#include <cmath>
#include <bitset>
using namespace std;

class UnionFind {
private:
  vector<int> par;

public:
  UnionFind(int N) {
    par.resize(N);
    iota(par.begin(), par.end(), 0);
  }

  int root(int x) {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

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

  void unite(int x, int y) {
    if (same(x, y)) return;
    x = root(x);
    y = root(y);
    par[y] = x;
  }
};

int main() {
  int n;
  cin >> n;
  vector<long long> x(n), y(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  vector<vector<long long>> d2(n, vector<long long>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      d2[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
      //printf("d2[%d][%d] = %lld\n", i, j, d2[i][j]);
    }



  long long ok = (long long)3e9;
  long long ng = 0;
  while (ng + 1 < ok) {
    long long x = (ok+ng)/2;
    UnionFind uf(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (x*x >= d2[i][j]) uf.unite(i, j);
    if (uf.same(0, n-1)) ok = x;
    else ng = x;
  }
  cout << (ok+9) / 10 * 10 << endl;
}
0