結果

問題 No.867 避難経路
ユーザー e869120e869120
提出日時 2019-08-15 11:18:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,558 bytes
コンパイル時間 1,264 ms
コンパイル使用メモリ 85,772 KB
実行使用メモリ 137,252 KB
最終ジャッジ日時 2023-10-19 18:50:16
合計ジャッジ時間 67,122 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,456 KB
testcase_01 AC 7 ms
9,456 KB
testcase_02 AC 7 ms
9,456 KB
testcase_03 AC 7 ms
9,456 KB
testcase_04 AC 7 ms
9,456 KB
testcase_05 AC 7 ms
9,456 KB
testcase_06 AC 7 ms
9,456 KB
testcase_07 AC 7 ms
9,456 KB
testcase_08 AC 7 ms
9,456 KB
testcase_09 AC 7 ms
9,456 KB
testcase_10 AC 7 ms
9,456 KB
testcase_11 AC 7 ms
9,456 KB
testcase_12 AC 7 ms
9,456 KB
testcase_13 AC 7 ms
9,456 KB
testcase_14 AC 7 ms
9,456 KB
testcase_15 AC 2,371 ms
132,392 KB
testcase_16 AC 2,262 ms
132,360 KB
testcase_17 AC 2,453 ms
134,104 KB
testcase_18 AC 2,255 ms
133,260 KB
testcase_19 AC 2,221 ms
133,324 KB
testcase_20 AC 2,202 ms
133,324 KB
testcase_21 AC 2,168 ms
133,324 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 12 ms
44,548 KB
testcase_42 AC 6 ms
7,908 KB
testcase_43 AC 6 ms
7,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long H, W, Q, gx, gy, A[259][259];
long long val[259][259][259], dist[259][259];
priority_queue<tuple<long long, int, int>, vector<tuple<long long, int, int>>, greater<tuple<long long, int, int>>> Que;

void dijkstra(long long r) {
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) dist[i][j] = (1LL << 62);
	}
	dist[gx][gy] = 1LL * (r*r + A[gx][gy]);
	Que.push(make_tuple(dist[gx][gy], gx, gy));

	int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0,1, 0, -1 };

	while (!Que.empty()) {
		tuple<long long, int, int> tup = Que.top(); Que.pop();
		int cx = get<1>(tup), cy = get<2>(tup);
		for (int i = 0; i < 4; i++) {
			int ex = cx + dx[i], ey = cy + dy[i];
			if (ex <= 0 || ey <= 0 || ex > H || ey > W) continue;

			long long cost = r * r + A[ex][ey];
			if (dist[ex][ey] > dist[cx][cy] + 1LL * cost) {
				dist[ex][ey] = dist[cx][cy] + 1LL * cost;
				Que.push(make_tuple(dist[ex][ey], ex, ey));
			}
		}
	}
}

int main() {
	scanf("%lld%lld%lld%lld", &H, &W, &gx, &gy);
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) scanf("%lld", &A[i][j]);
	}
	for (int i = 1; i <= 250; i++) {
		dijkstra(i);
		for (int j = 1; j <= H; j++) {
			for (int k = 1; k <= W; k++) val[i][j][k] = dist[j][k];
		}
	}
	scanf("%lld", &Q);
	for (int i = 1; i <= Q; i++) {
		long long cx, cy, k;
		scanf("%lld%lld%lld", &cx, &cy, &k); k = min(k, 250LL);
		printf("%lld\n", val[k][cx][cy]);
	}
	return 0;
}
0