結果

問題 No.2695 Warp Zone
ユーザー otoshigootoshigo
提出日時 2024-03-22 22:02:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,513 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 210,356 KB
実行使用メモリ 35,256 KB
最終ジャッジ日時 2024-03-22 22:02:08
合計ジャッジ時間 3,559 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 33 ms
35,256 KB
testcase_04 AC 31 ms
35,256 KB
testcase_05 AC 32 ms
35,256 KB
testcase_06 AC 32 ms
35,256 KB
testcase_07 AC 32 ms
35,256 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 14 ms
22,688 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 7 ms
14,180 KB
testcase_12 AC 18 ms
26,864 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 23 ms
29,100 KB
testcase_15 AC 14 ms
20,616 KB
testcase_16 AC 6 ms
12,100 KB
testcase_17 AC 10 ms
16,424 KB
testcase_18 AC 27 ms
33,200 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 26 ms
31,148 KB
testcase_21 AC 22 ms
29,096 KB
testcase_22 AC 12 ms
20,592 KB
testcase_23 AC 19 ms
26,864 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;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const ll INF=1LL<<60;
ll D[2010][2010];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll H,W;
    int N;
    cin>>H>>W>>N;
    vector<ll>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<ll>X(2*N+2),Y(2*N+2);
    X[0]=1,Y[0]=1;
    for(int i=0;i<N;i++){
        X[2*i+1]=a[i],Y[2*i+1]=b[i];
        X[2*i+2]=c[i],Y[2*i+2]=d[i];
    }
    X[2*N+1]=H,Y[2*N+1]=W;
    for(int i=0;i<=2*N+1;i++)for(int j=0;j<=2*N+1;j++)D[i][j]=INF;
    for(int i=0;i<N;i++){
        D[2*i+1][2*i+2]=1LL;
    }
    for(int i=0;i<=2*N+1;i++){
        for(int j=0;j<=2*N+1;j++){
            if(i==j)continue;
            chmin(D[i][j],abs(X[i]-X[j])+abs(Y[i]-Y[j]));
        }
    }
    vector<ll>dist(2*N+2,INF);
    dist[0]=0LL;
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>pq;
    pq.push(make_pair(dist[0],0));
    while(pq.size()){
        auto[c,x]=pq.top();
        pq.pop();
        if(dist[x]<c)continue;
        for(int i=0;i<=2*N+1;i++){
            if(i==x)continue;
            if(chmin(dist[i],c+D[x][i])){
                pq.push(make_pair(dist[i],i));
            }
        }
    }
    cout<<dist[2*N+1]<<"\n";
}
0