結果

問題 No.971 いたずらっ子
ユーザー polylogKpolylogK
提出日時 2020-01-17 21:31:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,443 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 178,936 KB
実行使用メモリ 42,440 KB
最終ジャッジ日時 2023-09-08 01:42:46
合計ジャッジ時間 9,439 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 652 ms
42,396 KB
testcase_04 AC 620 ms
39,824 KB
testcase_05 AC 663 ms
42,360 KB
testcase_06 AC 518 ms
30,936 KB
testcase_07 WA -
testcase_08 AC 170 ms
13,456 KB
testcase_09 AC 163 ms
12,868 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int h, w; scanf("%d%d", &h, &w); std::vector<std::string> s(h);
	for(int i = 0; i < h; i++) cin >> s[i];
	
	auto dp = make_v<i64>(h, w);
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) dp[i][j] = 1LL << 60;
	dp[0][0] = 0;
	
	std::vector<int> dx = {0, -1, 0, 1};
	std::vector<int> dy = {1, 0, -1, 0};
	using P = std::pair<i64, std::pair<int, int>>;
	std::priority_queue<P, std::vector<P>, std::greater<P>> qu; qu.push({0, {0, 0}});
	while(!qu.empty()) {
		auto p = qu.top(); qu.pop();
		int x = p.second.first, y = p.second.second, from = p.first;
		
		for(int k = 0; k < 4; k++) {
			int nx = x + dx[k], ny = y + dy[k];
			if(nx < 0 or ny < 0 or nx >= h or ny >= w) continue;
			if(s[nx][ny] == '.') {
				if(dp[nx][ny] <= dp[x][y] + 1) continue;
				dp[nx][ny] = dp[x][y] + 1;
				qu.push({dp[nx][ny], {nx, ny}});
			} else if(s[nx][ny] == 'k') {
				if(dp[nx][ny] <= dp[x][y] + (x + y) + 2) continue;
				dp[nx][ny] = dp[x][y] + (x + y) + 2;
				qu.push({dp[nx][ny], {nx, ny}});
			}
		}
	}
	
	printf("%lld\n", dp[h - 1][w - 1]);
	return 0;
}
0