結果

問題 No.168 ものさし
ユーザー xuzijian629xuzijian629
提出日時 2018-10-28 04:06:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,581 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 212,600 KB
実行使用メモリ 11,740 KB
最終ジャッジ日時 2024-04-29 22:22:43
合計ジャッジ時間 3,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,460 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 14 ms
5,460 KB
testcase_12 AC 43 ms
11,740 KB
testcase_13 AC 63 ms
11,616 KB
testcase_14 AC 59 ms
11,740 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 57 ms
11,616 KB
testcase_20 AC 59 ms
11,612 KB
testcase_21 AC 61 ms
11,608 KB
testcase_22 AC 59 ms
11,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

struct edge {
    int s, t;
    i64 dist;
};

vi par;

int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    par[x] = y;
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int n;
    cin >> n;
    vector<edge> edges;
    using ii = pair<i64, i64>;
    vector<ii> as;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        as.push_back(ii(x, y));
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            edges.push_back((edge){i, j, (as[i].first - as[j].first) * (as[i].first - as[j].first) + (as[i].second - as[j].second) * (as[i].second - as[j].second)});
        }
    }
    
    sort(edges.begin(), edges.end(), [](edge a, edge b) {return a.dist < b.dist;});
    par = vi(n);
    iota(par.begin(), par.end(), 0);
    
    i64 ans = 0;
    for (auto& e: edges) {
        if (same(0, n - 1)) break;
        if (same(e.s, e.t)) continue;
        i64 d = e.dist;
        i64 l = 0, r = 2e9;
        while (l < r - 1) {
            i64 m = (l + r) / 2;
            if (m * m <= d) {
                l = m;
            }  else {
                r = m;
            }
        }
        if (l * l == d) {
            ans = max(ans, (l + 9) / 10);
        } else {
            ans = max(ans, (l + 10) / 10);
        }
        unite(e.s, e.t);
    }
    cout << ans * 10 << endl;
}
0