結果

問題 No.168 ものさし
ユーザー recososorecososo
提出日時 2020-03-05 16:30:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 173,780 KB
実行使用メモリ 20,920 KB
最終ジャッジ日時 2023-08-04 04:15:46
合計ジャッジ時間 3,585 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,832 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 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,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 22 ms
8,436 KB
testcase_12 AC 70 ms
20,116 KB
testcase_13 AC 100 ms
20,920 KB
testcase_14 AC 99 ms
20,064 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 94 ms
19,964 KB
testcase_20 AC 99 ms
20,468 KB
testcase_21 AC 98 ms
19,796 KB
testcase_22 AC 98 ms
20,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int nmax=1005;
int par[nmax],siz[nmax];
void init(int x){
    for(int i=0;i<x;i++){
        par[i]=i;
        siz[i]=1;
    }
}
int root(int x){
    if(par[x]==x){
        return x;
    }
    return par[x]=root(par[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y){
        return ;
    }
    par[y]=x;
    siz[x]+=siz[y];
}
typedef long double ld;
ld x[nmax],y[nmax];
ld dis(int i,int j){
    return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
int main(){
    int n;cin >> n;
    init(n);
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    vector<pair<ld,pair<int,int>>> c;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            c.push_back({dis(i,j),{i,j}});
        }
    }
    long long ans=0;
    sort(c.begin(),c.end());
    for(int i=0;i<c.size();i++){
        unite(c[i].second.first,c[i].second.second);
        if(root(0)==root(n-1)){
            ans=ceil(c[i].first/(double)10)*10;
            break;
        }
    }
    cout << ans << endl;
}
0