結果

問題 No.2695 Warp Zone
ユーザー tkmstkms
提出日時 2024-03-03 13:34:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,282 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 178,608 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-03-03 14:21:28
合計ジャッジ時間 2,788 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 21 ms
11,520 KB
testcase_04 AC 21 ms
11,136 KB
testcase_05 AC 21 ms
11,136 KB
testcase_06 AC 21 ms
11,392 KB
testcase_07 AC 22 ms
11,520 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 9 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 11 ms
7,424 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 13 ms
8,576 KB
testcase_15 AC 9 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 5 ms
6,676 KB
testcase_18 AC 16 ms
9,472 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 15 ms
8,704 KB
testcase_21 AC 13 ms
8,448 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 11 ms
7,424 KB
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>
using namespace std;
int main(){
    long long H,W;
    int N;
    cin >> H >> W >> N;
    vector<long long> a(N), b(N), c(N),d(N);
    for(int i = 0; i < N;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    vector<vector<long long>> G(N+2, vector<long long>(N+2, -1));
    for(int i = 0; i < N;i++){
        G[0][i+1] = a[i] + b[i] - 1;
    }
    G[0][N+1] = H + W - 2;
    for(int i = 0; i < N;i++){
        for(int j = 0; j < N; j++){
            if(i == j){
                continue;
            }
            G[i+1][j+1] = abs(a[j] - c[i])+ abs(b[j] - d[i]) + 1;
        }
    }
    for(int i = 0; i < N;i++){
        G[i+1][N+1] = H - c[i] + W - d[i];
    }

    priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<pair<long long,int>>> que;
    que.push({0, 0});
    vector<long long> ans(N+2, 3e18);
    ans[0] = 0;
    while(!que.empty()){
        pair<long long, int> v = que.top();
        long long x = v.first;
        int y = v.second;
        que.pop();
        for(int i = 0; i < N + 2;i++){
            if(G[y][i] == -1 || ans[i] <= x + G[y][i]){
                continue;
            }
            ans[i] = x + G[y][i];
            que.push({x + G[y][i], i});
        }
    }
    cout << ans[N+1] << endl;
}
0