結果
問題 |
No.2179 Planet Traveler
|
ユーザー |
![]() |
提出日時 | 2022-09-06 15:40:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 100 ms / 3,000 ms |
コード長 | 1,196 bytes |
コンパイル時間 | 5,038 ms |
コンパイル使用メモリ | 260,568 KB |
最終ジャッジ日時 | 2025-02-07 03:08:24 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#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; template <class T> using V = vector<T>; template <class T> using PQ = priority_queue<T, V<T>, greater<T> >; ll isqrt(ll n) { double rn = sqrt(double(n)); ll ok = max(0ll, (ll)(rn - 5.0)); ll ng = (ll)(rn + 5.0); while (ng - ok > 1ll) { ll 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<ll> > que = {}; rep(i, 0, n-1) { ll r1 = squ(p[i][0]) + squ(p[i][1]); rep(j, i + 1, n) { ll r2 = squ(p[j][0]) + squ(p[j][1]); ll d = 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,(ll)i,(ll)j }); } } ll ans = 0ll; dsu uni(n); while (uni.same(0, n - 1) == false) { V<ll> v = que.top(); que.pop(); ans = v[0]; uni.merge(v[1], v[2]); } cout << ans << endl; return 0; }