結果

問題 No.168 ものさし
ユーザー kakakakanekokakakakaneko
提出日時 2018-04-12 22:54:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,790 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 105,596 KB
実行使用メモリ 17,204 KB
最終ジャッジ日時 2023-09-09 04:28:25
合計ジャッジ時間 3,148 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
6,256 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 17 ms
6,488 KB
testcase_12 AC 58 ms
16,672 KB
testcase_13 AC 80 ms
16,000 KB
testcase_14 AC 80 ms
16,036 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 66 ms
15,904 KB
testcase_20 AC 71 ms
16,652 KB
testcase_21 AC 70 ms
16,196 KB
testcase_22 AC 70 ms
17,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const double INF3 = 900000000000000;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()

ll par[100010], Rank[100010];

void init(int n) {
	for (int i = 0;i < n;i++)par[i] = i, Rank[i] = 0;
}
int find(ll x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}
void unite(ll x, ll 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]++;
	}
}
bool same(ll x, ll y) {
	return find(x) == find(y);
}


int main() {
	ll n, x[1010], y[1010], ans = INF2;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> x[i] >> y[i];
	}
	vector<pair<ll, P>>v;
	for (int i = 0;i < n - 1;i++)for (int j = i + 1;j < n;j++) {
		ll dis = (ll)sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		dis -= dis % 10;
		while (dis*dis < (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]))dis += 10;
		v.push_back(make_pair(dis, make_pair(i, j)));
	}
	sort(v.begin(), v.end());
	init(1010);
	for (int i = 0;i < v.size();i++) {
		if (!same(v[i].second.first, v[i].second.second)) {
			unite(v[i].second.first, v[i].second.second);
			ans = v[i].first;
		}
		if (find(0) == find(n - 1))break;
	}
	cout << ans << endl;
}
0