結果

問題 No.168 ものさし
ユーザー masamasa
提出日時 2015-06-30 01:22:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 79,472 KB
実行使用メモリ 12,988 KB
最終ジャッジ日時 2023-08-25 20:57:26
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,424 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 13 ms
5,124 KB
testcase_12 AC 43 ms
11,808 KB
testcase_13 AC 60 ms
12,988 KB
testcase_14 AC 60 ms
12,816 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 57 ms
12,280 KB
testcase_20 AC 59 ms
11,632 KB
testcase_21 AC 59 ms
12,200 KB
testcase_22 AC 60 ms
11,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;

typedef pair<long long, long long> PLL;


class UnionFind {
private:
	vector<int> parent;
	int trees;

public:
	UnionFind() {
	}

	UnionFind(int n) {
		trees = n;
		parent.assign(n, 0);

		for (int i = 0; i < n; i++) {
			parent[i] = i;
		}
	}

	int find(int x) {
		if (parent[x] == x) {
			return x;
		} else {
			return parent[x] = find(parent[x]);
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x != y) {
			parent[x] = y;
			trees--;
		}
	}

	int count() {
		return trees;
	}
};

int main() {
	int n, x, y;
	vector<PLL> points;

	cin >> n;
	points.assign(n, PLL());

	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		points[i] = make_pair(x, y);
	}

	vector<PLL> length2;

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			long long x = points[i].first  - points[j].first;
			long long y = points[i].second - points[j].second;

			length2.push_back(make_pair(x * x + y * y, i * 10000 + j));
		}
	}

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

	UnionFind uf(n);
	long long ans2 = -1;
	for (int i = 0; i < length2.size(); i++) {
		int x = length2[i].second / 10000;
		int y = length2[i].second % 10000;
		uf.unite(x, y);
		if (uf.same(0, n - 1)) {
			ans2 = length2[i].first;
			break;
		}
	}

	long long ans = sqrt(ans2);
	while(ans * ans < ans2) {
		ans++;
	}

	ans = (ans + 9) / 10 * 10;
	cout << ans << endl;
	return 0;
}
0