結果

問題 No.2179 Planet Traveler
ユーザー MasKoaTSMasKoaTS
提出日時 2022-09-06 16:01:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 3,000 ms
コード長 1,209 bytes
コンパイル時間 4,998 ms
コンパイル使用メモリ 273,868 KB
実行使用メモリ 24,064 KB
最終ジャッジ日時 2024-05-07 20:26:16
合計ジャッジ時間 6,568 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 46 ms
23,808 KB
testcase_12 AC 71 ms
23,800 KB
testcase_13 AC 73 ms
24,064 KB
testcase_14 AC 46 ms
23,800 KB
testcase_15 AC 47 ms
23,956 KB
testcase_16 AC 45 ms
23,808 KB
testcase_17 AC 85 ms
23,804 KB
testcase_18 AC 85 ms
23,932 KB
testcase_19 AC 75 ms
23,928 KB
testcase_20 AC 14 ms
5,984 KB
testcase_21 AC 96 ms
23,928 KB
testcase_22 AC 60 ms
13,808 KB
testcase_23 AC 39 ms
13,552 KB
testcase_24 AC 66 ms
17,476 KB
testcase_25 AC 46 ms
14,456 KB
testcase_26 AC 65 ms
23,932 KB
testcase_27 AC 11 ms
5,856 KB
testcase_28 AC 32 ms
13,544 KB
testcase_29 AC 70 ms
17,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <math.h>
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define squ(n) (n) * (n)
using namespace std;
using namespace atcoder;
using ll = long long;
using u64 = unsigned long long;
template <class T>	using V = vector<T>;
template <class T>	using PQ = priority_queue<T, V<T>, greater<T> >;

u64 isqrt(u64 n) {
	u64 ok = 0ll;
	u64 ng = 4000000000ll;
	while (ng - ok > 1ll) {
		u64 mid = (ok + ng) >> 1ll;
		if (mid * mid <= n) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}
	return ok;
}


int main(void) {
	int n;	cin >> n;
	V<V<ll> > p(n, V<ll>(3));
	rep(i, 0, n) {
		ll x, y, t;	cin >> x >> y >> t;
		p[i] = { x,y,t };
	}

	PQ<V<u64> > que = {};
	rep(i, 0, n-1) {
		u64 r1 = (u64)(squ(p[i][0]) + squ(p[i][1]));
		rep(j, i + 1, n) {
			u64 r2 = (u64)(squ(p[j][0]) + squ(p[j][1]));
			u64 d = (u64)(squ(p[i][0] - p[j][0]) + squ(p[i][1] - p[j][1]));
			if (p[i][2] != p[j][2]) {
				d = r1 + r2 - isqrt(4ll * r1 * r2);
			}
			que.push({ d,(u64)i,(u64)j });
		}
	}

	u64 ans = 0ll;
	dsu uni(n);
	while (uni.same(0, n - 1) == false) {
		V<u64> v = que.top();	que.pop();
		ans = v[0];
		uni.merge(v[1], v[2]);
	}
	cout << ans << endl;

	return 0;
}
0