結果

問題 No.168 ものさし
ユーザー koyumeishikoyumeishi
提出日時 2015-03-20 00:47:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 85,712 KB
実行使用メモリ 12,912 KB
最終ジャッジ日時 2023-08-25 20:46:35
合計ジャッジ時間 2,429 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,252 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,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 18 ms
5,076 KB
testcase_12 AC 60 ms
11,260 KB
testcase_13 AC 84 ms
11,644 KB
testcase_14 AC 82 ms
11,316 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 59 ms
12,912 KB
testcase_20 AC 62 ms
12,076 KB
testcase_21 AC 61 ms
11,892 KB
testcase_22 AC 61 ms
12,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

class UnionFindTree{
	typedef struct {
		int parent;
		int rank;
	}base_node;
	
	vector<base_node> node;
public:
	UnionFindTree(int n){
		node.resize(n);
		for(int i=0; i<n; i++){
			node[i].parent=i;
			node[i].rank=0;
		}
	}

	int find(int x){
		if(node[x].parent == x) return x;
		else{
			return node[x].parent = find(node[x].parent);
		}
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}

	void unite(int x, int y){
		x = find(node[x].parent);
		y = find(node[y].parent);
		if(x==y) return;
		if(node[x].rank < node[y].rank){
			node[x].parent = y;
		}else if(node[x].rank > node[y].rank){
			node[y].parent = x;
		}else{
			node[x].rank++;
			unite(x,y);
		}
	}
};

struct edge{
	int u;
	int v;
	long long cost;

	bool operator<(const edge& a) const{
		return this->cost < a.cost;
	}
};

bool ok(int n, vector<edge>& E, long long len){

	UnionFindTree uft(n);

	len *= len;

	for(auto& e: E){
		if(e.cost > len) break;
		if( !uft.same(e.u, e.v) ){
			uft.unite(e.u, e.v);
		}
	}

	return uft.same(0, n-1);
}

int main(){
	int N;
	cin >> N;
	vector<int> X(N), Y(N);
	for(int i=0; i<N; i++){
		cin >> X[i] >> Y[i];
	}

	vector<edge> E;
	for(int i=0; i<N; i++){
		for(int j=i+1; j<N; j++){
			E.push_back(edge{i, j, 1LL * abs(X[i] - X[j]) * abs(X[i] - X[j]) + 1LL * abs(Y[i] - Y[j]) * abs(Y[i] - Y[j])});
		}
	}

	sort(E.begin(), E.end());

	long long lb = 0;
	long long ub = 2000000000;
	while(ub-lb>1){
		long long med = (ub+lb)/2;
		bool valid = ok(N, E, med);
		if(valid){
			ub = med;
		}else{
			lb = med;
		}
	}

	cout << ((ub+9)/10) * 10 << endl;

	return 0;
}
0