結果

問題 No.168 ものさし
ユーザー lapilapi
提出日時 2019-07-03 14:35:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,270 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 108,796 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 09:22:49
合計ジャッジ時間 2,705 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
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 AC 2 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 2000000000 // 10^9
#define LLINF 1LL<<60

class UF {
private:
	std::vector<int> parent;
	std::vector<int> level;
	std::vector<int> num_member; // 同じグループに属するメンバーの数
								 // 自身込み

public:
	// コンストラクタ ※注意※ 0~nまでのn+1個を作る
	UF(int n) {
		for (int i = 0; i <= n; i++) {
			parent.push_back(i); //
			level.push_back(1);  // 木の深さ
			num_member.push_back(1);
		}
	}
	// 木の根を求める
	int root(int x) {
		if (parent[x] == x)return x;
		else return parent[x] = root(parent[x]);
	}

	// 同じ集合に属するメンバーの数を求める
	int numOfmember(int x) {
		if (parent[x] == x) return num_member[x];
		else return num_member[x] = numOfmember(parent[x]);
	}

	// xとyの属する集合を合併
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return; // 元々合併済みの場合
		if (level[rx] < level[ry]) {
			num_member[ry] = numOfmember(ry) + numOfmember(rx);
			parent[rx] = ry;
		}
		else {
			num_member[rx] = numOfmember(ry) + numOfmember(rx);
			parent[ry] = rx;
			if (level[rx] == level[ry]) level[rx]++;
		}
	}
	// xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return root(x) == root(y); // rootが同じなら同じ集合に含まれる
	}
};

ll X[1009], Y[1009];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	for (int i = 1; i <= N; i++) cin >> X[i] >> Y[i];



	ll left = 0; ll right = INF;
	// left < ans <= right

	while (left +10  != right) {
		UF uf(N);
		ll mid = (left + right) / 2;
		mid = (mid / 10) * 10;

		for (int i = 1; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				ll dis = (X[i] - X[j])*(X[i] - X[j]) + (Y[i] - Y[j])*(Y[i] - Y[j]);
				if (mid*mid >= dis) uf.unite(i, j);
			}
		}

		if (uf.numOfmember(1) == N) right = mid;
		else left = mid;
	}

	cout << right << endl;

	return 0;
}
0