結果

問題 No.168 ものさし
ユーザー kurenai3110kurenai3110
提出日時 2016-08-30 22:22:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,905 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 85,240 KB
実行使用メモリ 13,424 KB
最終ジャッジ日時 2024-04-26 21:22:20
合計ジャッジ時間 9,325 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAX 2e9;

vector<pair<long long, long long> >P;
int N;

struct UnionFind
{
	vector<int> par;
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		for (int i = 0; i < n; i++) par[i] = i;
	}

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

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

		if (x == y) return;

		if (sizes[x] < sizes[y]) swap(x, y);

		par[y] = x;
		sizes[x] += sizes[y];
	}

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

	int size(int x) {
		return sizes[find(x)];
	}
};

struct Edge {
	int a, b;
	long long cost;

	bool operator<(const Edge& o) const {
		return cost < o.cost;
	}
};

struct Graph {
	vector<Edge> es;

	bool kruskal(int d) {
		bool flag = true;
		sort(es.begin(), es.end());

		UnionFind uf(N);

		for (int ei = 0; ei < es.size(); ei++) {
			Edge& e = es[ei];
			if (!uf.same(e.a, e.b)) {
				if (e.cost > (long long)d*d) {
					flag = false;
					break;
				}

				uf.unite(e.a, e.b);
				if (uf.same(0, N - 1)) break;
			}
		}
		return flag;
	}
};

Graph input_graph() {
	Graph g;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			Edge e;
			e.a = i;
			e.b = j;
			e.cost = (P[i].first - P[j].first)*(P[i].first - P[j].first) + (P[i].second - P[j].second)*(P[i].second - P[j].second);
			cout << e.cost << endl;
			g.es.push_back(e);
		}
	}
	return g;
}


int main()
{
	cin >> N;

	P.resize(N);
	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		P[i] = make_pair(x, y);
	}

	Graph g = input_graph();

	long long left = 0;
	long long right = MAX;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (g.kruskal(mid)) {
			right = mid;
		}
		else {
			left = mid+1;
		}
	}

	cout << (int)ceil(mid/10.) * 10 << endl;

    return 0;
}
0