結果

問題 No.168 ものさし
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-30 21:43:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,721 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 66,876 KB
実行使用メモリ 11,444 KB
最終ジャッジ日時 2023-08-25 21:02:21
合計ジャッジ時間 2,211 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
7,568 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 6 ms
4,504 KB
testcase_11 AC 31 ms
7,428 KB
testcase_12 AC 94 ms
10,252 KB
testcase_13 AC 133 ms
11,380 KB
testcase_14 AC 132 ms
11,444 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 6 ms
4,932 KB
testcase_19 AC 56 ms
11,172 KB
testcase_20 AC 57 ms
11,332 KB
testcase_21 AC 60 ms
11,408 KB
testcase_22 AC 59 ms
11,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int n;
ll X[1010], Y[1010];
ll d[1010][1010];

class DisjointSet{
    public:
        vector<int> rank, p;//rank:木の高さ p:親の頂点番号
        DisjointSet(){}
        DisjointSet(int size){//頂点の数
            rank.resize(size, 0);
            p.resize(size, 0);
            rep(i, size) makeSet(i);
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        bool same(int x, int y){return findSet(x) == findSet(y);}
        void unite(int x, int y){link(findSet(x), findSet(y));}
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x] == rank[y]) rank[y]++;
            }
        }
        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

bool solve(ll len){
	DisjointSet ds = DisjointSet(n);
	rep(i, n)rep(j, n){
		if(d[i][j] <= len * len){
			ds.unite(i, j);
		}
	}
	return ds.same(0, n - 1);
}

int main(void){
	cin >> n;
	rep(i, n) cin >> X[i] >> Y[i];
	rep(i, n)rep(j, n){
		d[i][j] = (X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]);
	}

	ll left = 0, right = 1e10;
	while(right - left > 1){
		ll mid = (left + right) / 2;
		if(solve(mid)){
			right = mid;
		}else{
			left = mid + 1;
		}
	}
	// printf("%lld %lld\n", left, right);
	ll ans = left;
	for (int i = 0; i <= 11; ++i){
		if(ans % 10 == 0){
			if(solve(ans)) break;
		}
		ans++;
	}
	printf("%lld\n", ans);
	return 0;
}
0