結果

問題 No.2695 Warp Zone
ユーザー tkmstkms
提出日時 2024-02-15 18:57:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,937 bytes
コンパイル時間 4,424 ms
コンパイル使用メモリ 270,176 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-03-03 14:21:15
合計ジャッジ時間 5,519 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 20 ms
11,648 KB
testcase_04 AC 20 ms
11,264 KB
testcase_05 AC 20 ms
11,264 KB
testcase_06 AC 20 ms
11,520 KB
testcase_07 AC 20 ms
11,648 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 3 ms
6,676 KB
testcase_12 AC 10 ms
7,424 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 13 ms
8,576 KB
testcase_15 AC 8 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 16 ms
9,600 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 13 ms
8,832 KB
testcase_21 AC 13 ms
8,448 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 10 ms
7,424 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>
#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();
        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