結果

問題 No.94 圏外です。(EASY)
ユーザー xuzijian629xuzijian629
提出日時 2018-10-29 18:26:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,710 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 205,688 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 23:10:18
合計ジャッジ時間 3,179 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 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 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 8 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return true;
    if (rk[x] < rk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rk[x] == rk[y]) rk[x]++;
    }
    return false;
}

int main() {
    // assert(freopen("/Users/xuzijian/yukicoder/input", "r", stdin));
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    int n;
    cin >> n;
    vi xs(n), ys(n);
    for (int i = 0; i < n; i++) {
        cin >> xs[i] >> ys[i];
    }

    par = vi(n);
    rk = vi(n);
    iota(par.begin(), par.end(), 0);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            i64 d = i64(xs[i] - xs[j]) * (xs[i] - xs[j]) + i64(ys[i] - ys[j]) * (ys[i] - ys[j]);
            if (d <= 10 * 10) {
                unite(i, j);
            }
        }
    }

    double ans = 1;
    for (int i = 0; i < n; i++) {
        find(i);
    }
    
    vi used(n);
    for (int i = 0; i < n; i++) {
        if (used[par[i]]) continue;
        used[par[i]] = 1;
        vi ps;
        for (int j = 0; j < n; j++) {
            if (par[i] == par[j]) ps.push_back(j);
        }
        double d = 0;
        for (int j = 0; j < ps.size(); j++) {
            for (int k = j + 1; k < ps.size(); k++) {
                d = max(d, hypot(xs[ps[k]] - xs[ps[j]], ys[ps[k]] - ys[ps[j]]));
            }
        }
        ans = max(ans, d + 2);
    }
    cout << ans << endl;
}
0