結果

問題 No.168 ものさし
ユーザー kyunakyuna
提出日時 2019-08-17 00:52:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 83,184 KB
実行使用メモリ 12,176 KB
最終ジャッジ日時 2023-10-24 16:11:22
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,460 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 7 ms
5,460 KB
testcase_12 AC 16 ms
12,176 KB
testcase_13 AC 19 ms
12,176 KB
testcase_14 AC 18 ms
12,176 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 19 ms
12,176 KB
testcase_20 AC 19 ms
12,176 KB
testcase_21 AC 19 ms
12,176 KB
testcase_22 AC 19 ms
12,176 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0