結果

問題 No.2179 Planet Traveler
ユーザー nono00nono00
提出日時 2023-01-07 00:24:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 3,000 ms
コード長 1,757 bytes
コンパイル時間 2,774 ms
コンパイル使用メモリ 217,144 KB
実行使用メモリ 15,272 KB
最終ジャッジ日時 2023-08-20 17:46:34
合計ジャッジ時間 4,708 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 35 ms
13,916 KB
testcase_12 AC 33 ms
13,676 KB
testcase_13 AC 38 ms
13,772 KB
testcase_14 AC 35 ms
14,148 KB
testcase_15 AC 35 ms
13,764 KB
testcase_16 AC 36 ms
13,984 KB
testcase_17 AC 57 ms
15,272 KB
testcase_18 AC 43 ms
14,364 KB
testcase_19 AC 57 ms
15,268 KB
testcase_20 AC 7 ms
4,900 KB
testcase_21 AC 39 ms
13,396 KB
testcase_22 AC 25 ms
9,916 KB
testcase_23 AC 28 ms
9,592 KB
testcase_24 AC 43 ms
13,460 KB
testcase_25 AC 28 ms
10,316 KB
testcase_26 AC 50 ms
14,248 KB
testcase_27 AC 8 ms
4,928 KB
testcase_28 AC 22 ms
8,176 KB
testcase_29 AC 48 ms
13,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr double INF = 1e9;
constexpr double eps = 1e-10;

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 = max(.0, dist[n - 1] - eps);
    long long ans = ceil(s * s);
    cout << ans << endl;
}
0