結果
問題 |
No.2179 Planet Traveler
|
ユーザー |
![]() |
提出日時 | 2023-01-07 00:11:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,712 bytes |
コンパイル時間 | 2,233 ms |
コンパイル使用メモリ | 211,884 KB |
最終ジャッジ日時 | 2025-02-10 00:43:44 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 24 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; constexpr double INF = 1e9; vector<double> dijkstra(const vector<vector<pair<int, double>>> &graph, int s) { int n = graph.size(); priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> hp; vector<double> dist(n, INF); vector<bool> used(n, false); dist[s] = 0; hp.emplace(0, s); while (!hp.empty()) { auto [_, u] = hp.top(); hp.pop(); if (used[u]) continue; used[u] = true; for (auto [v, w]: graph[u]) { if (used[v]) continue; if (max(dist[u], w) < dist[v]) { dist[v] = max(dist[u], w); hp.emplace(dist[v], v); } } } return dist; } int main() { int n; cin >> n; vector<vector<int>> planets(n, vector<int>(3)); for (int i = 0; i < n; i++) { cin >> planets[i][0] >> planets[i][1] >> planets[i][2]; } vector<vector<pair<int, double>>> graph(n); for (int i = 0; i < n; i++) { graph[i].reserve(n); for (int j = 0; j < n; j++) { if (planets[i][2] == planets[j][2]) { graph[i].emplace_back(j, hypot(planets[i][0] - planets[j][0], planets[i][1] - planets[j][1])); } else { graph[i].emplace_back(j, abs(hypot(planets[i][0], planets[i][1]) - hypot(planets[j][0], planets[j][1]))); } } } vector<double> dist = dijkstra(graph, 0); double s = dist[n - 1]; long long ans = ceil(s * s); cout << ans << endl; }