結果

問題 No.2695 Warp Zone
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-03-30 17:45:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,319 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 216,216 KB
実行使用メモリ 67,968 KB
最終ジャッジ日時 2024-03-30 17:45:09
合計ジャッジ時間 5,098 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 94 ms
67,968 KB
testcase_04 AC 92 ms
66,688 KB
testcase_05 AC 92 ms
66,688 KB
testcase_06 AC 94 ms
67,584 KB
testcase_07 AC 95 ms
67,968 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 35 ms
28,160 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 12 ms
11,648 KB
testcase_12 AC 49 ms
38,272 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 62 ms
47,872 KB
testcase_15 AC 32 ms
25,344 KB
testcase_16 AC 10 ms
9,984 KB
testcase_17 AC 19 ms
16,512 KB
testcase_18 AC 76 ms
58,112 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 67 ms
51,968 KB
testcase_21 AC 65 ms
46,976 KB
testcase_22 AC 25 ms
19,584 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>
#include <atcoder/segtree>
using namespace atcoder;
using namespace std;
using ll = long long;
struct Edge {
	int to;
	ll cost;
};
using Graph = vector<vector<Edge>>;
ll INF = (1LL << 60);
void DJK(int s, vector<ll>& dist, Graph& G) {
	dist[s] = 0;
	priority_queue<pair<ll, int>, vector<pair<ll,int>>, greater<pair<ll, int>>> pq;
	int N = G.size();
	for (int v = 0;v < N;v++) pq.emplace(dist[v], v);
	while (!pq.empty()) {
		int v = pq.top().second;ll dis = pq.top().first;pq.pop();
		if (dist[v] < dis) continue;
		for (auto nv : G[v]) {
			ll cost = nv.cost + dis;
			if (cost < dist[nv.to]) {
				dist[nv.to] = cost;
				pq.emplace(dist[nv.to], nv.to);
			}
		}
	}
}
int main() {
	ll H, W;int N;cin >> H >> W >> N;
	int K = (2 * N) + 2;
	vector<pair<ll, ll>> pos;
	pos.push_back({1, 1});
	pos.push_back({H, W});
	Graph G(K);
	for (int i = 0;i < N;i++) {
		ll a, b, c,d;cin >> a >> b >> c >> d;
		pos.push_back({a,b});
		int x = pos.size() - 1;
		pos.push_back({c, d});
		int y = pos.size() - 1;
		G[x].push_back({y, 1});
	}
	for (int i = 0;i < K;i++) for (int j = 0;j < K;j++) {
		if (i == j) continue;
		ll dist = abs(pos[i].first - pos[j].first) + abs(pos[i].second - pos[j].second);
		G[i].push_back({j, dist});
	}
	vector<ll> dist(K, INF);
	DJK(0, dist, G);
	cout << dist[1] << endl;
}

0