結果

問題 No.2179 Planet Traveler
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-11 02:44:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,971 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 120,444 KB
実行使用メモリ 16,944 KB
最終ジャッジ日時 2023-08-31 01:41:14
合計ジャッジ時間 5,786 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 80 ms
16,160 KB
testcase_14 AC 42 ms
15,444 KB
testcase_15 AC 43 ms
16,024 KB
testcase_16 AC 44 ms
16,824 KB
testcase_17 AC 80 ms
15,916 KB
testcase_18 WA -
testcase_19 AC 82 ms
16,944 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 49 ms
10,348 KB
testcase_23 WA -
testcase_24 AC 66 ms
10,068 KB
testcase_25 AC 51 ms
10,768 KB
testcase_26 AC 75 ms
16,128 KB
testcase_27 WA -
testcase_28 AC 36 ms
10,372 KB
testcase_29 AC 65 ms
10,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;
using ll = long long;

struct UnionFind {
    int ngroup;
    vector<int> par;
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N) {
        ngroup = N;
        for(int i = 0; i < N; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }

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

    int unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return rx;
        ngroup--;
        if (siz[rx] > siz[ry]) swap(rx, ry);
        par[rx] = ry;
        siz[ry] += siz[rx];
        return ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){
        return siz[root(x)];
    }

    int group_count(){
        return ngroup;
    }
};

ll s(ll x){
    return x*x;
}

ll isqrt(ll s){
    ll l=0, r=3e9, c;
    while(r-l>1){
        c = (l+r)/2;
        if (c*c <= s) l = c;
        else r = c;
    }
    return l;
}

int main(){
 
    ll N, C, ans=0, R1, R2;
    cin >> N;
    vector<tuple<ll, ll, ll>> v;
    vector<ll> x(N), y(N), t(N);
    for (int i=0; i<N; i++) cin >> x[i] >> y[i] >> t[i];
    UnionFind tree(N+1);
    
    for (int i=0; i<N; i++){
        for (int j=i+1; j<N; j++){
            if (t[i] != t[j]){
                R1 = s(x[i]) + s(y[i]);
                R2 = s(x[j]) + s(y[j]);
                C = R1+R2-isqrt(R1*R2)*2;
            }
            else C = s(x[i]-x[j])+s(y[i]-y[j]);
            v.push_back({C, i+1, j+1});
        }
    }
    sort(v.begin(), v.end());
    for (auto [c, i, j] : v){
        if (!tree.same(1, N)){
            tree.unite(i, j);
            ans = c;
        }
    }

    cout << ans << endl;
 
    return 0;
}
0