結果

問題 No.971 いたずらっ子
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2020-01-18 16:12:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 777 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 177,280 KB
実行使用メモリ 42,496 KB
最終ジャッジ日時 2023-08-07 08:02:18
合計ジャッジ時間 8,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 777 ms
42,364 KB
testcase_01 AC 775 ms
42,416 KB
testcase_02 AC 563 ms
30,776 KB
testcase_03 AC 623 ms
42,268 KB
testcase_04 AC 588 ms
40,068 KB
testcase_05 AC 619 ms
42,496 KB
testcase_06 AC 460 ms
30,976 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 148 ms
13,592 KB
testcase_09 AC 143 ms
13,152 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int h, w; cin >> h >> w;
	string a[h]; for(int i = 0; i < h; ++i) cin >> a[i];
	priority_queue<tuple<int64_t, int, int>, vector<tuple<int64_t, int, int>>, greater<tuple<int64_t, int, int>>> pq;
	int64_t dp[h][w];
	for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) dp[i][j] = 1e18;
	dp[0][0] = 0;
	pq.emplace(0, 0, 0);
	while(not pq.empty()) {
		int64_t cost;
		int y, x;
		tie(cost, y, x) = pq.top();
		pq.pop();
		if(cost > dp[y][x]) continue;
		const int dy[] = {1, 0};
		const int dx[] = {0, 1};
		for(int d = 0; d < 2; ++d) {
			int ny = y + dy[d];
			if(h <= ny) continue;
			int nx = x + dx[d];
			if(w <= nx) continue;
			int64_t ncost = cost + 1;
			if(a[ny][nx] == 'k') {
				ncost += (ny + nx);
			}
			if(ncost >= dp[ny][nx]) continue;
			dp[ny][nx] = ncost;
			pq.emplace(ncost, ny, nx);
		}
	}
	cout << dp[h - 1][w - 1] << '\n';
	return 0;
}
0