結果

問題 No.2695 Warp Zone
ユーザー kokoseikokosei
提出日時 2024-03-22 22:08:57
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 2,810 ms
コンパイル使用メモリ 245,748 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-22 22:09:01
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 22 ms
6,676 KB
testcase_04 AC 21 ms
6,676 KB
testcase_05 AC 21 ms
6,676 KB
testcase_06 AC 22 ms
6,676 KB
testcase_07 AC 22 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 8 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
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 14 ms
6,676 KB
testcase_15 AC 7 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 5 ms
6,676 KB
testcase_18 AC 17 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 15 ms
6,676 KB
testcase_21 AC 14 ms
6,676 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 11 ms
6,676 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;
const int inf = (int)2e9 + 1;

int H, W, N;
int X[2020], Y[2020];
int dist[2020], used[2020];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> H >> W >> N;
    int cnt = 1;
    X[0] = 1, Y[0] = 1;
    for(int i = 0;i < N;i++){
        int a, b, c, d; cin >> a >> b >> c >> d;
        X[cnt] = a, Y[cnt] = b;
        cnt++;
        X[cnt] = c, Y[cnt] = d;
        cnt++;
    }
    X[cnt] = H, Y[cnt] = W; cnt++;
    for(int i = 1;i < cnt;i++)dist[i] = inf;
    while(1){
        int v = -1, d = inf;
        for(int i = 0;i < cnt;i++)if(!used[i]){
            if(d > dist[i])v = i, d = dist[i];
        }
        used[v] = 1;
        if(v == -1)break;
        for(int nv = 0;nv < cnt;nv++){
            ll tmp = d + abs(X[v] - X[nv]) + abs(Y[v] - Y[nv]);
            if(v % 2 == 1 && nv == v + 1)tmp = d + 1;
            if(tmp > inf)continue;
            int nd = tmp;
            dist[nv] = min(dist[nv], nd);
        }
    }
    cout << dist[cnt - 1] << endl;
    return 0;
}
0