結果

問題 No.971 いたずらっ子
ユーザー 夜
提出日時 2020-11-17 17:51:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 733 ms / 2,000 ms
コード長 1,848 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 105,232 KB
実行使用メモリ 43,008 KB
最終ジャッジ日時 2024-04-25 02:16:44
合計ジャッジ時間 7,413 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 727 ms
42,880 KB
testcase_01 AC 733 ms
43,008 KB
testcase_02 AC 540 ms
38,784 KB
testcase_03 AC 631 ms
42,752 KB
testcase_04 AC 591 ms
40,960 KB
testcase_05 AC 606 ms
42,880 KB
testcase_06 AC 450 ms
34,944 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 150 ms
18,048 KB
testcase_09 AC 144 ms
17,408 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 7 ms
11,520 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
string s[2020];
long long score[2020][2020];
int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
		for (int j = 0; j < w; j++) {
			score[i][j] = -1;
		}
	}
	score[0][0] = 0;
	set<pair<int, int>> st;
	priority_queue<tuple<long long, int, int>, vector<tuple<long long, int, int>>, greater<tuple<long long, int, int>>> que;
	long long ans = 1000000007;
	que.push(make_tuple(0, 0, 0));
	while (!que.empty()) {
		tuple<long long, int, int> p = que.top();
		int x = get<1>(p);
		int y = get<2>(p);
		long long z = get<0>(p);
		que.pop();
		if (score[x][y] != -1 && z > score[x][y]) {
			continue;
		}
		if (x == h - 1 && y == w - 1) {
			cout << z << endl;
			return 0;
		}
		if (x != h - 1) {
			if (s[x + 1][y] == 'k') {
				if (score[x + 1][y] == -1 || score[x + 1][y] > (z + 1) + x + 1 + y) {
					que.push(make_tuple((z + 1) + x + 1 + y, x + 1, y));
					score[x + 1][y] = (z + 1) + x + 1 + y;
				}
			}
			else {
				if (score[x + 1][y] == -1 || score[x + 1][y] > (z + 1)) {
					que.push(make_tuple(z + 1, x + 1, y));
					score[x + 1][y] = z + 1;
				}
			}
		}
		if (y != w - 1) {
			if (s[x][y + 1] == 'k') {
				if (score[x][y + 1] == -1 || score[x][y + 1] > (z + 1) + x + y + 1) {
					que.push(make_tuple((z + 1) + x + y + 1, x, y + 1));
					score[x][y + 1] = (z + 1) + x + 1 + y;
				}
			}
			else {
				if (score[x][y + 1] == -1 || score[x][y + 1] > (z + 1)) {
					que.push(make_tuple(z + 1, x, y + 1));
					score[x][y + 1] = z + 1;
				}
			}
		}
	}
}
0