結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 2024-03-22 22:08:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 93 ms / 2,000 ms |
コード長 | 1,732 bytes |
コンパイル時間 | 2,254 ms |
コンパイル使用メモリ | 211,284 KB |
最終ジャッジ日時 | 2025-02-20 11:43:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> #define int ll using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define rng(i,c,n) for(int i=c;i<n;i++) #define fi first #define se second #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) ((int) a.size()) #define vec(...) vector<__VA_ARGS__> #define _4ab8goq ios::sync_with_stdio(0),cin.tie(0); typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} void slv(){ int h,w,q; cin>>h>>w>>q; vec(array<int,4>) qry; rep(i,q){ int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty; sx-=1,sy-=1,tx-=1,ty-=1; qry.pb({sx,sy,tx,ty}); } vec(pii) tmp; rep(i,q){ auto [sx,sy,tx,ty]=qry[i]; tmp.pb({sx,sy}); tmp.pb({tx,ty}); } tmp.pb({0,0}); tmp.pb({h-1,w-1}); sort(all(tmp)); tmp.erase(unique(all(tmp)),tmp.end()); const int si=sz(tmp); vec(vec(pii)) adj(si); rep(i,q){ auto [sx,sy,tx,ty]=qry[i]; int u=lower_bound(all(tmp),pii{sx,sy})-tmp.begin(); int v=lower_bound(all(tmp),pii{tx,ty})-tmp.begin(); adj[u].pb({1,v}); } rep(i,si){ rep(j,si){ if(i==j) continue; int w=abs(tmp[i].fi-tmp[j].fi)+abs(tmp[i].se-tmp[j].se); adj[i].pb({w,j}); } } const int inf=1e18; vi dp(si,inf); dp[0]=0; priority_queue<pii,vec(pii),greater<pii>> pq; pq.push({0,0}); while(sz(pq)){ auto top=pq.top(); auto [cosu,v]=top; pq.pop(); if(dp[v]!=cosu) continue; for(auto [w,u]:adj[v]){ if(dp[u]>cosu+w){ dp[u]=cosu+w; pq.push({cosu+w,u}); } } } // rep(i,si){ // print(tmp[i].fi,tmp[i].se,dp[i]); // } cout<<dp.back()<<"\n"; } signed main(){ _4ab8goq; slv(); }