結果

問題 No.2695 Warp Zone
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-03-22 22:08:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,581 bytes
コンパイル時間 2,574 ms
コンパイル使用メモリ 215,340 KB
実行使用メモリ 67,840 KB
最終ジャッジ日時 2024-03-22 22:08:11
合計ジャッジ時間 4,490 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 95 ms
67,840 KB
testcase_04 AC 91 ms
66,560 KB
testcase_05 AC 92 ms
66,560 KB
testcase_06 AC 94 ms
67,584 KB
testcase_07 AC 94 ms
67,840 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 36 ms
28,544 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 12 ms
11,648 KB
testcase_12 AC 48 ms
38,528 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 60 ms
47,744 KB
testcase_15 AC 31 ms
25,344 KB
testcase_16 AC 11 ms
9,984 KB
testcase_17 AC 19 ms
16,384 KB
testcase_18 AC 74 ms
57,984 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 67 ms
52,096 KB
testcase_21 AC 60 ms
46,976 KB
testcase_22 AC 27 ms
19,584 KB
testcase_23 AC 48 ms
38,144 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;

vector<ll> dijkstra(vector<vector<pair<ll, ll>>> &E, ll start){
 
    ll N = E.size();
    ll from, alt, d;

    pq<pair<ll, ll>> que;
    vector<ll> dist(N, 1e18);
    vector<bool> vst(N);
 
    dist[start] = 0;
    que.push({0, start});
 
    while(!que.empty()){
        tie(d, from) = que.top();
        que.pop();
        if (vst[from]) continue;
        vst[from] = 1;
        for (auto [to, C] : E[from]){
            alt = d + C;
            if (alt < dist[to]){
                dist[to] = alt;
                que.push({dist[to], to});
            }
        }
    }
 
    return dist;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll H, K, W, N, cnt=0;
    cin >> H >> W >> N;

    vector<ll> a(N), b(N), c(N), d(N), h(N*2+2), w(N*2+2);

    for (int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

    for (int i=0; i<N; i++){
        h[i+1] = a[i];
        w[i+1] = b[i]; 
        h[i+1+N] = c[i];
        w[i+1+N] = d[i];
    }
    h[0] = 1;
    w[0] = 1;
    h[2*N+1] = H;
    w[2*N+1] = W;

    vector<vector<pair<ll, ll>>> E(N*2+2);

    for (int i=0; i<2*N+2; i++){
        for (int j=0; j<2*N+2; j++){
            if (i==j) continue;
            E[i].push_back({j, abs(h[i]-h[j])+abs(w[i]-w[j])}); 
        }
    }
    for (int i=0; i<N; i++){
        E[i+1].push_back({i+1+N, 1LL});
    }

    vector<ll> dist = dijkstra(E, 0);

    cout << dist[2*N+1] << endl;

    return 0;
}
0