結果

問題 No.168 ものさし
ユーザー MisterMister
提出日時 2020-09-03 18:57:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,817 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 93,776 KB
実行使用メモリ 12,284 KB
最終ジャッジ日時 2023-08-15 14:02:20
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
5,128 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 12 ms
5,200 KB
testcase_12 AC 41 ms
12,284 KB
testcase_13 AC 56 ms
11,516 KB
testcase_14 AC 57 ms
12,016 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 54 ms
11,392 KB
testcase_20 AC 56 ms
11,648 KB
testcase_21 AC 57 ms
12,000 KB
testcase_22 AC 56 ms
11,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <tuple>

struct UnionFind {
    std::vector<int> par, sz;
    int gnum;

    explicit UnionFind(int n)
        : par(n), sz(n, 1), gnum(n) {
        std::iota(par.begin(), par.end(), 0);
    }

    int find(int v) {
        return (par[v] == v) ? v : (par[v] = find(par[v]));
    }

    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (sz[u] < sz[v]) std::swap(u, v);
        sz[u] += sz[v];
        par[v] = u;
        --gnum;
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return sz[find(v)]; }
};

using lint = long long;

lint dist(lint x, lint y) { return x * x + y * y; }

void solve() {
    int n;
    std::cin >> n;

    std::vector<std::pair<lint, lint>> ps(n);
    for (auto& [x, y] : ps) std::cin >> x >> y;

    std::vector<std::tuple<lint, int, int>> es;
    for (int i = 0; i < n; ++i) {
        auto [lx, ly] = ps[i];

        for (int j = 0; j < i; ++j) {
            auto [rx, ry] = ps[j];
            es.emplace_back(dist(rx - lx, ry - ly), i, j);
        }
    }

    std::sort(es.begin(), es.end());

    UnionFind uf(n);
    lint cost = 0;
    for (auto [c, u, v] : es) {
        if (uf.same(u, v)) continue;
        cost = std::max(cost, c);
        uf.unite(u, v);
        if (uf.same(0, n - 1)) break;
    }

    lint ok = 200000000, ng = 0;
    while (ok - ng > 1) {
        auto mid = (ok + ng) / 2;
        if (mid * mid * 100 >= cost) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    std::cout << ok * 10 << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0