結果

問題 No.168 ものさし
ユーザー なおなお
提出日時 2015-03-20 01:01:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,435 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 156,136 KB
実行使用メモリ 12,324 KB
最終ジャッジ日時 2023-08-25 20:48:03
合計ジャッジ時間 3,006 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
5,080 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 13 ms
5,260 KB
testcase_12 AC 41 ms
11,508 KB
testcase_13 AC 58 ms
11,880 KB
testcase_14 AC 58 ms
11,736 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 55 ms
12,324 KB
testcase_20 AC 57 ms
11,512 KB
testcase_21 AC 58 ms
11,836 KB
testcase_22 AC 57 ms
11,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t)        for(int(i)=(f);(i)<(t);(++i))
#define EACH(it, c)         for(auto it=(c).begin();it!=(c).end();++it)
const int MOD = int(1e9+7);

int N,M,W,H;

ll X[1111],Y[1111];

class uf_ {
public:
    vector<int> node;
    uf_(int n) : node(n, -1){;}
    void con(int n, int m){
        n = root(n); m = root(m); if(n == m) return;
        node[n] += node[m]; node[m] = n;
    }
    bool is_con(int n, int m){ return root(n) == root(m); }
    int root(int n){ return (node[n] < 0) ? n : node[n] = root(node[n]); }
    int size(int n){ return -node[root(n)]; }
};

int main(){
    do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0);
    cin >> N;
    REP(i,N) cin >> X[i] >> Y[i];

    vector<pair<ll,pair<int,int> > > v;
    REP(i,N) FOR(j,i+1,N){
        ll d = (X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]);
        v.push_back(make_pair(d, make_pair(i,j)));
    }

    sort(v.begin(), v.end());
    uf_ uf(N);

    ll d = 0;
    EACH(it, v){
        d = it->first;
        int u = it->second.first, v = it->second.second;
        uf.con(u,v);
        if(uf.is_con(0,N-1)) break;
    }

    ll res = int(sqrt(d+.0)/10)*10;
    while(res*res < d) res+=10;

    cout << res << endl;
    return 0;
}
0