結果

問題 No.168 ものさし
ユーザー TwizzTwizz
提出日時 2017-05-25 00:45:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 1,398 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 152,464 KB
実行使用メモリ 34,700 KB
最終ジャッジ日時 2023-08-25 21:05:48
合計ジャッジ時間 4,657 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
10,448 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 3 ms
4,384 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 41 ms
9,812 KB
testcase_12 AC 229 ms
25,196 KB
testcase_13 AC 374 ms
34,580 KB
testcase_14 AC 366 ms
34,700 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,384 KB
testcase_18 AC 9 ms
4,912 KB
testcase_19 AC 333 ms
33,396 KB
testcase_20 AC 363 ms
34,612 KB
testcase_21 AC 364 ms
34,600 KB
testcase_22 AC 368 ms
34,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"

using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
const ll mod = 10000000000;
//union-find木実装
int par[100002];
int ran[100002];

//初期化
void init(int n) {
	rep(i, 0, n) {
		par[i] = i;
		ran[i] = 0;
	}
}

//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (ran[x] < ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ran[x] == ran[y])ran[x]++;
	}
}

//xとyが同じ集合かどうか
bool same(int x, int y) {
	return find(x) == find(y);
}

int main() {
	int n;
	ll x[1002], y[1002];
	ll ans = 0;
	map<ll,PI> eg;
	cin >> n;
	REP(i, n)cin >> x[i] >> y[i];
	init(n); 
	REP(i, n)rep(j, i + 1, n) {
		eg.insert(make_pair((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]), make_pair(i, j)));
	}
	for (auto itr = eg.begin(); itr != eg.end(); ++itr) {
		PI e = itr->second;
		if (!same(e.first, e.second)) {
			unite(e.first, e.second);
			ll d = itr->first;
			ans = max(ans, d);
		}
		if (same(0, n - 1))break;
	}
	ll c = sqrt(ans);
	while (c*c < ans)c += 1;
	print((int)((c+9)/10*10));
	return 0;
}
0