結果

問題 No.2695 Warp Zone
ユーザー shobonvipshobonvip
提出日時 2024-03-23 04:11:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 2,390 bytes
コンパイル時間 7,951 ms
コンパイル使用メモリ 286,020 KB
実行使用メモリ 35,456 KB
最終ジャッジ日時 2024-03-23 04:11:41
合計ジャッジ時間 6,967 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 46 ms
35,456 KB
testcase_04 AC 42 ms
34,176 KB
testcase_05 AC 43 ms
34,176 KB
testcase_06 AC 44 ms
35,200 KB
testcase_07 AC 44 ms
35,456 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 16 ms
13,952 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 22 ms
18,560 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 28 ms
22,912 KB
testcase_15 AC 15 ms
12,672 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 9 ms
8,832 KB
testcase_18 AC 35 ms
27,776 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 33 ms
24,960 KB
testcase_21 AC 27 ms
22,528 KB
testcase_22 AC 13 ms
11,648 KB
testcase_23 AC 23 ms
18,432 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>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

// defcomp
template <typename T>
vector<T> compress(vector<T> &X) {
	vector<T> vals = X;
	sort(vals.begin(), vals.end());
	vals.erase(unique(vals.begin(), vals.end()), vals.end());
	return vals;
}
// -----

int main(){
	ll h, w, n; cin >> h >> w >> n;
	vector<pair<ll,ll>> points;
	vector<ll> a(n),b(n),c(n),dd(n);
	rep(i,0,n){
		cin >> a[i] >> b[i] >> c[i] >> dd[i];
		points.push_back(pair(a[i], b[i]));
		points.push_back(pair(c[i], dd[i]));
	}
	points.push_back(pair(1, 1));
	points.push_back(pair(h, w));
	points = compress(points);
	map<pair<ll,ll>,int> taio;
	int m = points.size();
	rep(i,0,m){
		taio[points[i]] = i;
	}

	vector dist(m, vector<ll>(m,1e18));
	rep(i,0,n){
		int x = taio[pair(a[i], b[i])];
		int y = taio[pair(c[i], dd[i])];
		chmin(dist[x][y], 1LL);
	}
	rep(i,0,m){
		rep(j,0,m){
			ll x1 = points[i].first;
			ll x2 = points[j].first;
			ll y1 = points[i].second;
			ll y2 = points[j].second;
			chmin(dist[i][j], abs(x1-x2) + abs(y1-y2));
		}
	}

	vector<ll> d(m,(ll)1e18);
	priority_queue<pair<ll,int>> pq;
	d[taio[pair(1,1)]] = 0;
	pq.push(pair(0, taio[pair(1,1)]));
	while(!pq.empty()){
		auto [tmp, i] = pq.top();
		pq.pop();
		tmp = -tmp;
		if (tmp > d[i]) continue;
		rep(j,0,m){
			ll targ = tmp + dist[i][j];
			if (chmin(d[j], targ)){
				pq.push(pair(-d[j],j));
			}
		}
	}

	cout << d[taio[pair(h,w)]] << '\n';
}

0