結果

問題 No.168 ものさし
ユーザー kyuna
提出日時 2019-08-17 00:52:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 83,484 KB
実行使用メモリ 12,952 KB
最終ジャッジ日時 2024-09-24 07:10:48
合計ジャッジ時間 2,098 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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> using min_heap = priority_queue<T, vector<T>, greater<T>>;
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; }
};
ll cur;
ll check(ll x) {
return cur <= x * x;
}
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() {
int n; cin >> n;
vector<long long> x(n), y(n);
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
min_heap<pair<long long, pair<int, int>>> pq;
for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
long long d = dist2(x[j] - x[i], y[j] - y[i]);
pq.emplace(d, make_pair(i, j));
}
UnionFind uf(n);
long long ans = 1;
while (true) {
cur = pq.top().first;
ans = (binary_search(INF, 0) + 9) / 10 * 10;
int a = pq.top().second.first, b = pq.top().second.second;
pq.pop();
uf.unionSet(a, b);
if (uf.findSet(0, n - 1)) break;
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0