結果

問題 No.2695 Warp Zone
ユーザー Today03Today03
提出日時 2024-03-22 22:08:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,948 bytes
コンパイル時間 2,404 ms
コンパイル使用メモリ 217,668 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-22 22:08:50
合計ジャッジ時間 3,447 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,676 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

template <typename T>
vector<T> dijkstra(const vector<vector<pair<int, T>>> &G, int start = 0) {
    int n = G.size();
    vector<T> dst(n, numeric_limits<T>::max());
    priority_queue<pair<T, int>> pq;
    dst[start] = 0;
    pq.push(make_pair(0, start));
    while (!pq.empty()) {
        auto [dst_sum, now] = pq.top();
        pq.pop();
        dst_sum = -dst_sum;
        if (dst[now] < dst_sum) continue;
        for (auto [nxt, cost] : G[now]) {
            if (dst[nxt] > dst[now] + cost) {
                dst[nxt] = dst[now] + cost;
                pq.push(make_pair(-dst[nxt], nxt));
            }
        }
    }
    return dst;
}

int main() {
    int H, W, N;
    cin >> H >> W >> N;

    vector<array<int, 4>> E(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            cin >> E[i][j];
            E[i][j]--;
        }
    }

    vector<vector<pair<int, ll>>> G(2 * N + 2);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            G[2 * N].push_back({2 * i, E[i][0] + E[i][1]});
            G[2 * i].push_back({2 * N, E[i][0] + E[i][1]});
            G[2 * N + 1].push_back({2 * i, H - E[i][0] + W - E[i][1] - 2});
            G[2 * i].push_back({2 * N + 1, H - E[i][0] + W - E[i][1] - 2});
            G[2 * N].push_back({2 * i + 1, E[i][2] + E[i][3]});
            G[2 * i + 1].push_back({2 * N, E[i][2] + E[i][3]});
            G[2 * N + 1].push_back({2 * i + 1, H - E[i][2] + W - E[i][3] - 2});
            G[2 * i + 1].push_back({2 * N + 1, H - E[i][2] + W - E[i][3] - 2});
            G[2 * i].push_back({2 * i + 1, 1});
        }
    }
    G[2 * N].push_back({2 * N + 1, H + W - 2});
    G[2 * N + 1].push_back({2 * N, H + W - 2});

    vector<ll> dst = dijkstra(G, 2 * N);

    cout << dst[2 * N + 1] << endl;
}
0