結果
問題 | No.2695 Warp Zone |
ユーザー | askr58 |
提出日時 | 2024-03-22 22:34:41 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,693 bytes |
コンパイル時間 | 5,852 ms |
コンパイル使用メモリ | 319,728 KB |
実行使用メモリ | 19,712 KB |
最終ジャッジ日時 | 2024-03-22 22:34:48 |
合計ジャッジ時間 | 6,866 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 22 ms
19,712 KB |
testcase_04 | AC | 21 ms
19,456 KB |
testcase_05 | AC | 21 ms
19,456 KB |
testcase_06 | AC | 21 ms
19,584 KB |
testcase_07 | AC | 22 ms
19,712 KB |
testcase_08 | AC | 2 ms
6,548 KB |
testcase_09 | AC | 10 ms
10,752 KB |
testcase_10 | AC | 2 ms
6,548 KB |
testcase_11 | AC | 5 ms
6,548 KB |
testcase_12 | AC | 13 ms
13,696 KB |
testcase_13 | AC | 2 ms
6,548 KB |
testcase_14 | AC | 16 ms
16,000 KB |
testcase_15 | AC | 9 ms
9,984 KB |
testcase_16 | AC | 5 ms
6,548 KB |
testcase_17 | AC | 6 ms
6,656 KB |
testcase_18 | AC | 18 ms
17,536 KB |
testcase_19 | AC | 2 ms
6,548 KB |
testcase_20 | AC | 18 ms
16,640 KB |
testcase_21 | AC | 16 ms
15,872 KB |
testcase_22 | AC | 7 ms
7,552 KB |
testcase_23 | AC | 14 ms
13,568 KB |
testcase_24 | AC | 2 ms
6,548 KB |
testcase_25 | AC | 2 ms
6,548 KB |
testcase_26 | AC | 1 ms
6,548 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll=long long; ll inf=1000000000000000001; struct warp{ ll x1,x2,y1,y2; warp(){} warp(ll x1,ll y1,ll x2,ll y2):x1(x1),y1(y1),x2(x2),y2(y2){}; }; struct edge{ int from,to; ll w; edge(){} edge(int f,int t,ll w):from(f),to(t),w(w){} }; int main() { ll h,w; int n; cin>>h>>w>>n; vector<warp> warps(n); for(int i=0;i<n;i++){ ll a,b,c,d; cin>>a>>b>>c>>d; warps[i]=warp(a,b,c,d); } vector<vector<edge>> graph(2*n+2); auto f=[](ll x1,ll y1,ll x2,ll y2)->ll{ return abs(x2-x1)+abs(y2-y1); }; graph[0].push_back(edge(0,2*n+1,h+w-2)); for(int i=0;i<n;i++){ graph[0].push_back(edge(0,i+1,f(1,1,warps[i].x1,warps[i].y1))); graph[n+1+i].push_back(edge(n+1+i,2*n+1,f(warps[i].x2,warps[i].y2,h,w))); } for(int i=0;i<n;i++){ graph[i+1].push_back(edge(i+1,n+i+1,1)); for(int j=0;j<n;j++){ if(j==i)continue; graph[n+i+1].push_back(edge(n+i+1,j+1,f(warps[i].x2,warps[i].y2,warps[j].x1,warps[j].y1))); } } vector<ll> distance(2*n+2,inf); using pli=pair<ll,int>; priority_queue<pli,vector<pli>,greater<pli>> pq; pq.push(make_pair(0,0)); while(!pq.empty()){ auto [c,p]=pq.top(); pq.pop(); if(distance[p]<c)continue; else distance[p]=c; for(edge e:graph[p]){ if(distance[e.to]<=c+e.w)continue; else{ distance[e.to]=c+e.w; pq.push(make_pair(c+e.w,e.to)); } } } cout<<distance[2*n+1]<<endl; }