結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-17 21:31:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,396 bytes |
| コンパイル時間 | 1,789 ms |
| コンパイル使用メモリ | 180,572 KB |
| 実行使用メモリ | 89,416 KB |
| 最終ジャッジ日時 | 2024-06-25 18:46:42 |
| 合計ジャッジ時間 | 8,511 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 20 |
ソースコード
#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};
std::priority_queue<std::pair<i64, std::pair<int, int>>> 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;
}