結果

問題 No.2179 Planet Traveler
ユーザー MasKoaTS
提出日時 2022-09-06 21:23:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 79 ms / 3,000 ms
コード長 1,496 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 209,940 KB
最終ジャッジ日時 2025-02-07 03:15:27
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define squ(n) (n) * (n)
using namespace std;
using ll = long long;
using u64 = unsigned long long;
using Pair = pair<u64, u64>;
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 = 0ull;
	u64 ng = 4000000000ull;
	while (ng - ok > 1ull) {
		u64 mid = (ok + ng) >> 1ull;
		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 };
	}

	V<V<Pair> > route(n, V<Pair>({}));
	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(4ull * r1 * r2);
			}
			route[i].push_back({ (u64)j,d });
			route[j].push_back({ (u64)i,d });
		}
	}

	V<u64> path(n, 1000000000000000000ull);
	PQ<Pair> que = {};
	que.push({ 0ull,0ull });
	while (que.empty() == false) {
		Pair pa = que.top();	que.pop();
		u64 v = pa.second, d = pa.first;
		if (path[v] <= d) {
			continue;
		}
		path[v] = d;
		if (v == n - 1) {
			break;
		}
		for (Pair npa : route[v]) {
			u64 nv = npa.first, nd = npa.second;
			que.push({ max(d,nd),nv });
		}
	}

	u64 ans = path[n - 1];
	cout << ans << endl;

	return 0;
}
0