結果

問題 No.2695 Warp Zone
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-22 21:53:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 226,624 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-22 21:53:37
合計ジャッジ時間 5,776 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 237 ms
6,548 KB
testcase_04 AC 235 ms
6,548 KB
testcase_05 AC 240 ms
6,548 KB
testcase_06 AC 237 ms
6,548 KB
testcase_07 AC 237 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 68 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 15 ms
6,548 KB
testcase_12 AC 94 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 129 ms
6,548 KB
testcase_15 AC 67 ms
6,548 KB
testcase_16 AC 13 ms
6,548 KB
testcase_17 AC 33 ms
6,548 KB
testcase_18 AC 167 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 141 ms
6,548 KB
testcase_21 AC 131 ms
6,548 KB
testcase_22 AC 48 ms
6,548 KB
testcase_23 AC 91 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    long long H,W; cin >> H >> W;
    int N; cin >> N;
    map<pair<int,int>,pair<int,int>> Graph;
    map<pair<int,int>,int> dist;
    for(int i=0; i<N; i++){
        int a,b,c,d; cin >> a >> b >> c >> d;
        Graph[{a,b}] = {c,d};
        dist[{a,b}] = 2e9+9; dist[{c,d}] = 2e9+9;
    }
    dist[{1,1}] = 0; dist[{H,W}] = 2e9+9;
    priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<>> Q;
    Q.push({0,1,1});
    while(Q.size()){
        auto [d,x,y] = Q.top(); Q.pop();
        if(dist[{x,y}] > d) continue;

        auto [x2,y2] = Graph[{x,y}];
        if(x2 != 0) if(dist[{x2,y2}] > d+1) dist[{x2,y2}] = d+1,Q.push({d+1,x2,y2});
        
        for(auto [p,d3] : dist){
            auto [x3,y3] = p;
            long long nc = d;
            nc += abs(x-x3); nc += abs(y-y3);
            if(nc < d3) dist[p] = nc,Q.push({nc,x3,y3});
        }  
    }
    


    cout << dist[{H,W}] << endl;
}
0