結果
問題 | No.2179 Planet Traveler |
ユーザー |
![]() |
提出日時 | 2024-12-03 15:32:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 78 ms / 3,000 ms |
コード長 | 1,403 bytes |
コンパイル時間 | 2,322 ms |
コンパイル使用メモリ | 210,744 KB |
最終ジャッジ日時 | 2025-02-26 10:47:44 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/dsu>using namespace std;using namespace atcoder;using ll = long long;ll isqrt(ll n) {ll ok = 0ll;ll ng = 2000000000ll;while(abs(ok - ng) > 1){ll mid = (ok + ng) / 2;if(mid * mid <= n){ok = mid;}else{ng = mid;}}return ok;}ll pow_ll(ll a, int b){ll ret = 1;for(int i = 0; i < b; ++i){ret *= a;}return ret;}int main(){int n; cin >> n;vector<tuple<ll, ll, int> > planets(n);for(auto&[x, y, z] : planets){cin >> x >> y >> z;}vector<tuple<ll, int, int> > edges = {};for(int i = 0; i < n - 1; ++i){auto&[x1, y1, t1] = planets[i];for(int j = i + 1; j < n; ++j){auto&[x2, y2, t2] = planets[j];ll d = pow_ll(x1 - x2, 2) + pow_ll(y1 - y2, 2);if(t1 != t2){ll r1 = x1 * x1 + y1 * y1;ll r2 = x2 * x2 + y2 * y2;d = r1 + r2 - isqrt(4 * r1 * r2);}edges.push_back({d, i, j});}}sort(edges.begin(), edges.end());dsu uni(n);ll ans = 0;for(auto&[d, x, y] : edges){ans = d;uni.merge(x, y);if(!uni.same(0, n - 1)){continue;}break;}cout << ans << endl;return 0;}