結果

問題 No.2695 Warp Zone
ユーザー aradarad
提出日時 2024-03-22 22:02:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,955 bytes
コンパイル時間 6,047 ms
コンパイル使用メモリ 318,168 KB
実行使用メモリ 35,200 KB
最終ジャッジ日時 2024-03-22 22:03:08
合計ジャッジ時間 7,086 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 47 ms
35,200 KB
testcase_04 AC 45 ms
34,048 KB
testcase_05 AC 46 ms
34,048 KB
testcase_06 AC 46 ms
34,816 KB
testcase_07 AC 46 ms
35,200 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 15 ms
13,696 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 6 ms
6,656 KB
testcase_12 AC 23 ms
18,432 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 28 ms
22,656 KB
testcase_15 AC 13 ms
12,544 KB
testcase_16 AC 5 ms
6,548 KB
testcase_17 AC 9 ms
8,704 KB
testcase_18 AC 37 ms
27,392 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 32 ms
24,576 KB
testcase_21 AC 30 ms
22,272 KB
testcase_22 AC 13 ms
11,520 KB
testcase_23 AC 22 ms
18,176 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using P = pair<ll,ll>;
using VP = vector<P>;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define out(x) cout << x << endl
#define dout(x) cout << fixed << setprecision(10) << x << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)(x.size())
#define re0 return 0
#define pcnt __builtin_popcountll
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int inf = 1e9;
constexpr ll INF = 1e18;
//using mint = modint1000000007;
using mint = modint998244353;
int di[4] = {1,0,-1,0};
int dj[4] = {0,1,0,-1};

int main(){
    ll h,w,n;
    cin >> h >> w >> n;
    VL a(n),b(n),c(n),d(n);
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    n++;
    a.emplace_back(h);
    b.emplace_back(w);
    c.emplace_back(1);
    d.emplace_back(1);
    VVL dist(n*2,VL(n*2,INF));
    rep(i,n)rep(j,n){
        //ig->js
        dist[i*2+1][j*2] = abs(c[i]-a[j])+abs(d[i]-b[j]);
        //jg->is
        dist[j*2+1][i*2] = abs(a[i]-c[j])+abs(d[j]-b[i]);
    }
    rep(i,n){
        dist[i*2][i*2+1] = 1;
        dist[i*2+1][i*2] = abs(a[i]-c[i])+abs(b[i]-d[i]);
    }
    VL dist0(n*2,INF);
    dist0[(n-1)*2+1] = 0;
    priority_queue<P,VP,greater<P>> pq;
    pq.emplace(dist0[(n-1)*2+1],(n-1)*2+1);
    while(sz(pq)){
        auto [d,v] = pq.top();
        pq.pop();
        if(dist0[v] < d) continue;
        rep(i,n*2){
            if(chmin(dist0[i],dist0[v]+dist[v][i])){
                pq.emplace(dist0[i],i);
            }
        }
    }
    out(dist0[(n-1)*2]);
}
0