結果

問題 No.2695 Warp Zone
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2024-03-22 23:06:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,014 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 212,048 KB
実行使用メモリ 67,968 KB
最終ジャッジ日時 2024-03-22 23:06:20
合計ジャッジ時間 4,608 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 134 ms
67,712 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,548 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 14 ms
11,008 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,548 KB
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
	ll H, W; int N;
	cin >> H >> W >> N;
	std::vector<ll> X(N * 2 + 2), Y(N * 2 + 2);
	X[0] = Y[0] = 1;
	X[1] = W, Y[1] = H;
	using P = pair<ll, int>;
	vector<P> gr[2020];
	{
		ll d = H - 1 + W - 1;
		gr[0].emplace_back(d, 1);
		gr[1].emplace_back(d, 0);
	}
	for (int i = 2; i < N * 2 + 2; i ++) {
		cin >> Y[i] >> X[i];
		for (int j = 0; j < i; j ++) {
			ll d = abs(X[i] - X[j]) + abs(Y[i] - Y[j]);
			gr[j].emplace_back(d, i);
			gr[i].emplace_back(d, j);
		}
	}
	for (int i = 1; i <= N; i ++) {
		int p = i * 2, q = i * 2 + 1;
		gr[p].emplace_back(1, q);
		gr[q].emplace_back(1, p);
	}
	priority_queue<P, vector<P>, greater<P>> pque;
	pque.emplace(0, 0);
	vector<ll> D(N * 2 + 2, (ll)1e18);
	D[0] = 0;
	while (!pque.empty()) {
		auto [l, u] = pque.top();
		pque.pop();
		if (l != D[u]) continue;
		for (auto& [d, v] : gr[u]) {
			if (D[v] > d + l) {
				D[v] = d + l;
				pque.emplace(D[v], v);
			}
		}
	}
	cout << D[1] << endl;
}
0