結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 2024-03-22 21:53:49 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,217 ms / 2,000 ms |
コード長 | 1,165 bytes |
コンパイル時間 | 5,501 ms |
コンパイル使用メモリ | 322,720 KB |
実行使用メモリ | 69,308 KB |
最終ジャッジ日時 | 2024-09-30 11:23:19 |
合計ジャッジ時間 | 15,665 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#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]; }