結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 92 ms
66,560 KB
testcase_05 AC 92 ms
66,560 KB
testcase_06 AC 93 ms
67,456 KB
testcase_07 AC 94 ms
67,840 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 38 ms
28,288 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 13 ms
11,776 KB
testcase_12 AC 49 ms
38,016 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 61 ms
47,488 KB
testcase_15 AC 32 ms
25,216 KB
testcase_16 AC 10 ms
9,856 KB
testcase_17 AC 19 ms
16,256 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 59 ms
46,720 KB
testcase_22 AC 25 ms
19,328 KB
testcase_23 AC 49 ms
37,760 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;
template<typename T>
vector<T> dijkstra(vector<vector<pair<int,T>>>&g, const T INF, int s=0)
{
    int n=g.size();
    vector<T>dist(n,INF);
    dist[s]=0;
    priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>>q;
    q.push(make_pair(T(0),s));
    while(!q.empty())
    {
        auto[d,u]=q.top();
        q.pop();
        if(dist[u]<d)continue;
        for(auto[v,w]:g[u])
        {
            if(dist[v]>d+w)
            {
                dist[v]=d+w;
                q.push(make_pair(dist[v],v));
            }
        }
    }
    return dist;
}
long H,W,N,A[2020],B[2020];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>H>>W>>N;
    for(int i=0;i<N;i++)cin>>A[i]>>B[i]>>A[i+N]>>B[i+N];
    vector<vector<pair<int,long>>>G(2*N+2);
    for(int i=0;i<2*N;i++)for(int j=0;j<2*N;j++)if(i!=j)
    {
        if(i+N==j)G[i].push_back(make_pair(j,1));
        else G[i].push_back(make_pair(j,abs(A[j]-A[i])+abs(B[j]-B[i])));
    }
    for(int i=0;i<2*N;i++)
    {
        G[2*N].push_back(make_pair(i,A[i]+B[i]-2));
        G[i].push_back(make_pair(2*N+1,H+W-A[i]-B[i]));
    }
    G[2*N].push_back(make_pair(2*N+1,H+W-2));
    cout<<(dijkstra(G,1L<<60,2*N)[2*N+1])<<endl;
}
0