結果

問題 No.2695 Warp Zone
ユーザー t98slidert98slider
提出日時 2024-03-22 21:44:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 220,740 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-03-22 21:44:57
合計ジャッジ時間 4,020 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 58 ms
34,816 KB
testcase_04 AC 49 ms
33,536 KB
testcase_05 AC 49 ms
33,536 KB
testcase_06 AC 50 ms
34,560 KB
testcase_07 AC 51 ms
34,816 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 17 ms
13,568 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 25 ms
18,048 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 31 ms
22,400 KB
testcase_15 AC 15 ms
12,160 KB
testcase_16 AC 5 ms
6,676 KB
testcase_17 AC 9 ms
8,448 KB
testcase_18 AC 38 ms
27,136 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 34 ms
24,320 KB
testcase_21 AC 31 ms
22,016 KB
testcase_22 AC 13 ms
11,136 KB
testcase_23 AC 24 ms
17,920 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;
using ll = long long;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll h, w, n;
	cin >> h >> w >> n;
	vector<tuple<int,int,int,int>> edge(n);
	vector<pair<int,int>> ca;
	ca.emplace_back(1, 1);
	ca.emplace_back(h, w);
	for(auto &&[a, b, c, d] : edge){
		cin >> a >> b >> c >> d;
		ca.emplace_back(a, b);
		ca.emplace_back(c, d);
	}
	sort(ca.begin(), ca.end());
	int m = ca.size();
	vector<vector<ll>> A(m, vector<ll>(m, 1ll << 60));
	for(auto [a, b, c, d] : edge){
		int v = lower_bound(ca.begin(), ca.end(), make_pair(a, b)) - ca.begin();
		int u = lower_bound(ca.begin(), ca.end(), make_pair(c, d)) - ca.begin();
		A[v][u] = 1;
	}
	for(int i = 0; i < m; i++) A[i][i] = 0;
	for(int u = 0; u < m; u++){
		for(int v = 0; v < m; v++){
			A[u][v] = min(A[u][v], abs((ll)ca[u].first - ca[v].first) + abs(ca[u].second - ca[v].second));
		}
	}
	vector<ll> dp(m, 1ll << 60);
	vector<bool> used(m);
	dp[0] = 0;
	for(int i = 0; i < m; i++){
		int u = -1;
		ll mn = 1ll << 60;
		for(int j = 0; j < m; j++){
			if(used[j]) continue;
			if(dp[j] < mn){
				mn = dp[j];
				u = j;
			}
		}
		if(u == -1) continue;
		used[u] = true;
		for(int v = 0; v < m; v++){
			dp[v] = min(dp[v], dp[u] + A[u][v]);
		}
	}
	cout << dp.back() << '\n';
}
0