結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2019-01-01 21:04:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 73 ms / 2,000 ms |
コード長 | 1,330 bytes |
コンパイル時間 | 1,472 ms |
コンパイル使用メモリ | 167,196 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-11-08 02:18:13 |
合計ジャッジ時間 | 2,778 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#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;}