結果
| 問題 | No.2695 Warp Zone | 
| コンテスト | |
| ユーザー |  nonon | 
| 提出日時 | 2024-03-22 22:17:31 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,233 bytes | 
| コンパイル時間 | 2,425 ms | 
| コンパイル使用メモリ | 205,896 KB | 
| 最終ジャッジ日時 | 2025-02-20 11:50:29 | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 6 WA * 18 | 
ソースコード
#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;
}
int 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 if(A[i]<=A[j]&&B[i]<=B[j])G[i].push_back(make_pair(j,A[j]+B[j]-A[i]-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]));
    }
    cout<<(dijkstra(G,1L<<60,2*N)[2*N+1])<<endl;
}
            
            
            
        