結果
| 問題 |
No.168 ものさし
|
| コンテスト | |
| ユーザー |
task4233
|
| 提出日時 | 2019-01-01 21:01:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,335 bytes |
| コンパイル時間 | 1,704 ms |
| コンパイル使用メモリ | 166,756 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-11-08 02:15:34 |
| 合計ジャッジ時間 | 2,755 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 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*100LL) uf.merge(i, j);
}
}
return uf.issame(0, n-1);
};
// 範囲は[ng, ok).
int64_t ng = 0LL, ok = (1LL << 31);
while (ok-ng > 1) {
int64_t mid = (ok+ng)/2LL;
(check(mid) ? ok : ng) = mid;
}
int64_t ans = ok * 10LL;
cout << ans << endl;
return 0;
}
task4233