結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2020-10-23 16:00:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,689 bytes |
コンパイル時間 | 1,838 ms |
コンパイル使用メモリ | 178,192 KB |
実行使用メモリ | 13,008 KB |
最終ジャッジ日時 | 2024-07-21 10:16:32 |
合計ジャッジ時間 | 3,405 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;struct UnionFind {vector<int> data;UnionFind(int n) {data.assign(n, -1);}bool unite(int x, int y) {x = root(x), y = root(y);if (x == y)return (false);if (data[x] > data[y])swap(x, y);data[x] += data[y];data[y] = x;return (true);}int root(int k) {if (data[k] < 0)return (k);return (data[k] = root(data[k]));}bool same(int x, int y) {return root(x) == root(y);}int size(int k) {return (-data[root(k)]);}};int main() {int N;ll X[1010], Y[1010];cin >> N;for (int i = 0; i < N; i++) {cin >> X[i] >> Y[i];}auto len_sqrt = [&](int i, int j) {ll dx = abs(X[i] - X[j]), dy = abs(Y[i] - Y[j]);return dx * dx + dy * dy;};vector<pair<ll, pair<int, int>>> len;for (int i = 0; i < N; i++) {for (int j = 0; j < i; j++) {len.push_back({len_sqrt(i, j), {i, j}});}}sort(len.begin(), len.end());UnionFind uf(N);ll ans = 0;for (auto& e : len) {auto p = e.second;uf.unite(p.first, p.second);ans = e.first;if (uf.same(0, N - 1))break;}auto check = [&](ll x) {return x * x >= ans;};ll ok = 2e9;ll ng = 0;while (abs(ok - ng) > 1) {int mid = (ok + ng) / 2;if (check(mid)) {ok = mid;} else {ng = mid;}}ok = (ok + 9) / 10 * 10;cout << ok << endl;}