結果

問題 No.2695 Warp Zone
ユーザー たたき@競プロたたき@競プロ
提出日時 2024-03-22 21:53:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,397 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 5,564 ms
コンパイル使用メモリ 323,708 KB
実行使用メモリ 69,832 KB
最終ジャッジ日時 2024-03-22 21:54:14
合計ジャッジ時間 19,050 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1,375 ms
69,748 KB
testcase_04 AC 1,335 ms
69,744 KB
testcase_05 AC 1,313 ms
69,744 KB
testcase_06 AC 1,349 ms
69,748 KB
testcase_07 AC 1,397 ms
69,748 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 369 ms
37,016 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 80 ms
12,240 KB
testcase_12 AC 562 ms
37,044 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 760 ms
69,704 KB
testcase_15 AC 290 ms
37,012 KB
testcase_16 AC 61 ms
12,236 KB
testcase_17 AC 153 ms
20,456 KB
testcase_18 AC 1,003 ms
69,728 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 863 ms
69,712 KB
testcase_21 AC 715 ms
69,832 KB
testcase_22 AC 240 ms
20,472 KB
testcase_23 AC 567 ms
37,044 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;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int h,w,n;cin>>h>>w>>n;
  vc<pp>g;
  vc v(0,vc<int>(0));
  map<pp,int>m;
  auto f=[&](pp p)->void{
    if(m.count(p))return;
    m[p]=g.size();
    g.pb(p);
    v.pb(vc<int>(0));
    return;
  };
  f({0,0}); f({h-1,w-1});
  rep(i,n){
    pp a,b;
    cin>>a.fi>>a.se>>b.fi>>b.se;
    a.fi--,a.se--,b.fi--,b.se--;
    f(a); f(b);
    v[m[a]].pb(m[b]);
  }
  n=g.size();
  vc<ll>d(n,1e18);
  pque<pair<ll,int>>q;
  q.push({0,0});
  while(q.size()){
    auto [xx,a]=q.top(); q.pop();
    xx=-xx;
    if(xx>=d[a])continue;
    d[a]=xx;
    for(auto au:v[a])q.push({-d[a]-1,au});
    rep(i,n)if(i!=a){
      ll x=(ll)abs(g[i].fi-g[a].fi)+abs(g[i].se-g[a].se);
      q.push({-d[a]-x,i});
    }
  }
  //rep(i,n)cout<<d[i]<<' ';
  cout<<d[1];
}
  
0