結果

問題 No.168 ものさし
ユーザー niimi
提出日時 2018-10-08 01:06:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,635 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 160,380 KB
実行使用メモリ 11,260 KB
最終ジャッジ日時 2024-10-12 14:24:40
合計ジャッジ時間 2,666 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ll;
typedef std::pair<int, int> P;

#define frep(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) frep(i, 0, (n))
#define rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define all(i, x) for(typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 1010;
const int INF = 1e9;
const int MOD = 1000000007;
const string END = "\n";

struct UF{
	int par[MAX], rank[MAX];
	void init(int n){
		rep(i, n){
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x){
		if(par[x] == x){
			return x;  // 一番上のノードの時
		}else{
			return par[x] = find(par[x]);  // 上へ遡る
		}
	}
	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x] += 1;
		}
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int n;
ll x[MAX], y[MAX], d[MAX][MAX];

bool check(ll len){
	UF uf;
	uf.init(n);
	rep(i, n) rep(j, n){
		if(d[i][j] <= len * len){
			uf.unite(i, j);
		}
	}
	return uf.same(0, n-1);
}

void solve(){
	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 = (right + left) / 2;
		if(check(mid)){
			right = mid;
		}else{
			left = mid;
		}
	}
	ll ans = (right + 9) / 10 * 10;
	cout << ans << END;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	solve();
	return 0;
}
0