結果

問題 No.2695 Warp Zone
ユーザー inksamuraiinksamurai
提出日時 2024-03-22 22:08:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,732 bytes
コンパイル時間 2,712 ms
コンパイル使用メモリ 219,836 KB
実行使用メモリ 67,840 KB
最終ジャッジ日時 2024-03-22 22:08:40
合計ジャッジ時間 4,587 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 93 ms
67,840 KB
testcase_04 AC 91 ms
66,560 KB
testcase_05 AC 91 ms
66,560 KB
testcase_06 AC 92 ms
67,584 KB
testcase_07 AC 92 ms
67,840 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 36 ms
28,160 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 12 ms
11,136 KB
testcase_12 AC 48 ms
38,144 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 61 ms
47,616 KB
testcase_15 AC 31 ms
25,216 KB
testcase_16 AC 10 ms
9,856 KB
testcase_17 AC 19 ms
16,256 KB
testcase_18 AC 74 ms
58,112 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 68 ms
52,224 KB
testcase_21 AC 60 ms
46,848 KB
testcase_22 AC 26 ms
19,456 KB
testcase_23 AC 49 ms
37,888 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>
#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();
}
0