結果

問題 No.168 ものさし
ユーザー recososorecososo
提出日時 2020-03-05 16:30:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 1,824 ms
コンパイル使用メモリ 174,224 KB
実行使用メモリ 21,684 KB
最終ジャッジ日時 2024-04-22 02:37:05
合計ジャッジ時間 3,460 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
7,924 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 22 ms
8,552 KB
testcase_12 AC 74 ms
21,684 KB
testcase_13 AC 104 ms
20,104 KB
testcase_14 AC 104 ms
20,584 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 7 ms
6,944 KB
testcase_19 AC 99 ms
21,468 KB
testcase_20 AC 103 ms
21,464 KB
testcase_21 AC 102 ms
20,008 KB
testcase_22 AC 103 ms
20,516 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