結果

問題 No.168 ものさし
ユーザー niiminiimi
提出日時 2018-10-08 01:06:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,635 bytes
コンパイル時間 1,447 ms
コンパイル使用メモリ 160,360 KB
実行使用メモリ 11,280 KB
最終ジャッジ日時 2024-04-20 18:25:51
合計ジャッジ時間 2,886 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,168 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 21 ms
6,784 KB
testcase_12 AC 60 ms
9,952 KB
testcase_13 AC 81 ms
11,264 KB
testcase_14 AC 82 ms
11,212 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 43 ms
10,964 KB
testcase_20 AC 44 ms
11,228 KB
testcase_21 AC 46 ms
11,216 KB
testcase_22 AC 44 ms
11,280 KB
権限があれば一括ダウンロードができます

ソースコード

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