結果

問題 No.168 ものさし
ユーザー maine_honzukimaine_honzuki
提出日時 2020-06-04 19:25:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,689 bytes
コンパイル時間 2,724 ms
コンパイル使用メモリ 176,868 KB
実行使用メモリ 12,700 KB
最終ジャッジ日時 2023-08-20 01:20:20
合計ジャッジ時間 3,354 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
5,236 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 15 ms
5,228 KB
testcase_12 AC 46 ms
11,832 KB
testcase_13 AC 65 ms
12,096 KB
testcase_14 AC 65 ms
12,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,384 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 63 ms
12,700 KB
testcase_20 AC 65 ms
11,988 KB
testcase_21 AC 65 ms
12,120 KB
testcase_22 AC 65 ms
12,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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