結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 2024-03-22 22:42:50 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 1,436 bytes |
コンパイル時間 | 3,367 ms |
コンパイル使用メモリ | 259,888 KB |
実行使用メモリ | 35,712 KB |
最終ジャッジ日時 | 2024-09-30 12:08:17 |
合計ジャッジ時間 | 4,325 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define ALL(v) v.begin(), v.end()typedef long long ll;#include <bits/stdc++.h>using namespace std;const ll INF=1LL<<60;struct Edge{int to;ll w;Edge(int to,ll w) : to(to),w(w) {}};using Graph=vector<vector<Edge>>;using pli=pair<ll,int>;template<class T> bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}int main(){ios::sync_with_stdio(false);std::cin.tie(nullptr);ll h,w,n;cin>>h>>w>>n;vector<ll> A(n),B(n),C(n),D(n);rep(i,n){cin>>A[i]>>B[i]>>C[i]>>D[i];A[i]--,B[i]--,C[i]--,D[i]--;}Graph G(2*n+2);rep(i,n){G[i].push_back(Edge(i+n,1));}G[2*n].push_back(Edge(2*n+1,h+w-2));rep(i,n){G[2*n].push_back(Edge(i,A[i]+B[i]));G[i+n].push_back(Edge(2*n+1,h+w-2-C[i]-D[i]));}rep(i,n){rep(j,n){G[i].push_back(Edge(j,abs(A[i]-A[j])+abs(B[i]-B[j])));G[i+n].push_back(Edge(j,abs(C[i]-A[j])+abs(D[i]-B[j])));}}vector<ll> dist(2*n+2,INF);int s=2*n;dist[s]=0;priority_queue<pli,vector<pli>,greater<pli>> que;que.push({dist[s],s});while(!que.empty()){int v=que.top().second;ll d=que.top().first;que.pop();if(d>dist[v]) continue;for(auto e:G[v]){if(chmin(dist[e.to],dist[v]+e.w)){que.push({dist[e.to],e.to});}}}cout<<dist[2*n+1]<<endl;return 0;}