結果

問題 No.2695 Warp Zone
ユーザー tkmstkms
提出日時 2024-02-15 19:15:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,968 bytes
コンパイル時間 4,026 ms
コンパイル使用メモリ 236,936 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-03-03 14:21:21
合計ジャッジ時間 5,053 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<atcoder/all>
#include <bits/stdc++.h>
#include<atcoder/all>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define all(x) (x).begin(), (x).end()
#define YeNo(a) cout<<((a)?"Yes":"No")<<endl;
#define YENO(a) cout<<((a)?"YES":"NO")<<endl;
#define Ye cout<<"Yes"<<endl
#define YE cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Vcin(a) rep(i,a.size())cin>>a[i];
#define println(n) cout<<n<<endl
#define printsp(n) cout<<n<<" "
#define print(n) cout<<n
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vec vector
#define fin do{return 0;}while(0)
using namespace std;
using namespace atcoder;
using ll=long long;
using ull=unsigned long long;
using mint1=modint998244353;
using mint2=modint1000000007;
vector<int>dx={0,1,0,-1,-1,-1,1,1};
vector<int>dy={1,0,-1,0,-1,1,-1,1};
int INF=1e9;
ll LINF=1e18;
signed main(){
    ll H,W;
    int N;
    cin>>H>>W>>N;
    vec<ll>a(N);
    vec<ll>b(N);
    vec<ll>c(N);
    vec<ll>d(N);
    rep(i,N)cin>>a[i]>>b[i]>>c[i]>>d[i];
    vec<vec<ll>>G(N+2,vec<ll>(N+2,-1));
    rep(i,N){
        G[0][i+1]=a[i]+b[i]-1;
    }
    G[0][N+1]=H+W-2;
    rep(i,N){
        rep(j,N){
            if(i==j)continue;
            G[i+1][j+1]=abs(a[j]-c[i])+abs(b[j]-d[i])+1;
        }
    }
    rep(i,N){
        G[i+1][N+1]=H-c[i]+W-d[i];
    }
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> que;
    que.push({0,0});
    vec<ll>ans(N+2,LINF);
    ans[0]=0;
    while(!que.empty()){
        pair<ll,int>v=que.top();
        ll x=v.first;
        int y=v.se;
        que.pop();
        if(ans[y]<=x)continue;
        rep(i,N+2){
            if(G[y][i]==-1)continue;
            if(ans[i]<=x+G[y][i])continue;
            else{
                ans[i]=x+G[y][i];
                que.push({x+G[y][i],i});
            }
        }
    }
    println(ans[N+1]);
}
0