結果

問題 No.168 ものさし
ユーザー masamasa
提出日時 2015-06-30 11:07:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,296 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 81,400 KB
実行使用メモリ 28,336 KB
最終ジャッジ日時 2023-08-25 20:57:33
合計ジャッジ時間 1,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
8,588 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 10 ms
8,316 KB
testcase_12 AC 19 ms
18,088 KB
testcase_13 AC 34 ms
28,336 KB
testcase_14 AC 17 ms
19,168 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 24 ms
22,860 KB
testcase_20 AC 21 ms
21,080 KB
testcase_21 AC 34 ms
28,172 KB
testcase_22 AC 25 ms
23,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

typedef pair<long long, long long> PLL;

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< vector<PLL> > length2(n, vector<PLL>(n, PLL()));

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

			length2[i][j] = make_pair(x * x + y * y, i * 10000 + j);
		}
	}

	vector<bool> reach(n, false);
	priority_queue<PLL, vector<PLL>, greater<PLL> > que;
	for (int i = 1; i < n; i++) {
		que.push(length2[0][i]);
	}
	reach[0] = true;

	long long ans2 = -1;
	while (!que.empty()) {
		auto val = que.top();
		que.pop();

		ans2 = max(ans2, val.first);

		int to = val.second % 10000;
		if (to == n - 1) {
			break;
		} else if (reach[to]) {
			continue;
		}

		reach[to] = true;
		for (int i = 0; i < n; i++) {
			if (!reach[i]) {
				que.push(length2[to][i]);
			}
		}
	}

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

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