結果
| 問題 |
No.168 ものさし
|
| ユーザー |
kyuna
|
| 提出日時 | 2019-08-17 11:32:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 96 ms / 2,000 ms |
| コード長 | 1,612 bytes |
| コンパイル時間 | 1,214 ms |
| コンパイル使用メモリ | 85,020 KB |
| 実行使用メモリ | 13,244 KB |
| 最終ジャッジ日時 | 2024-09-24 19:03:54 |
| 合計ジャッジ時間 | 2,268 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
const int INF = (int)1.5e9;
using ll = long long;
template<class T> T dist2(T x, T y) { return x * x + y * y; }
struct UnionFind {
vector<int> data;
int sz;
UnionFind(int sz) : data(sz, -1), sz(sz) { }
bool unionSet(int x, int y) {
if ((x = root(x)) == (y = root(y))) return false;
if (data[x] > data[y]) swap(x, y);
data[x] += data[y]; data[y] = x; sz--;
return true;
}
bool findSet(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
int size() { return sz; }
};
int n;
vector<pair<ll, pair<int, int>>> ds;
ll check(ll x) {
UnionFind uf(n);
for (auto &p: ds) {
if (p.first > x * x) break;
uf.unionSet(p.second.first, p.second.second);
}
return uf.findSet(0, n - 1);
}
ll binary_search(ll ok, ll ng) {
assert(check(ok) == true);
assert(check(ng) == false);
while (abs(ng - ok) > 1) {
ll mid = (ng + ok) / 2;
(check(mid) ? ok : ng) = mid;
}
return ok;
}
int main() {
cin >> n;
vector<ll> x(n), y(n);
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
ll d = dist2(x[j] - x[i], y[j] - y[i]);
ds.emplace_back(d, make_pair(i, j));
}
sort(ds.begin(), ds.end());
ll ans = (binary_search(INF, 0) + 9) / 10 * 10;
cout << ans << endl;
return 0;
}
kyuna