結果
問題 | No.971 いたずらっ子 |
ユーザー |
|
提出日時 | 2020-01-20 00:25:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,127 ms / 2,000 ms |
コード長 | 878 bytes |
コンパイル時間 | 2,782 ms |
コンパイル使用メモリ | 207,776 KB |
最終ジャッジ日時 | 2025-01-08 20:15:47 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int H, W; cin >> H >> W; vector<string> G(H); for (int i = 0; i < H; ++i) { cin >> G[i]; } const int INF = 0x3f3f3f3f; vector<vector<int>> dp(H, vector<int>(W, INF)); set<tuple<int, int, int>> pq; pq.emplace(dp[0][0] = 0, 0, 0); while (pq.size()) { int d; int x, y; tie(d, x, y) = *pq.begin(); pq.erase(pq.begin()); if (d != dp[x][y]) continue; static int dx[] = { 1, 0 }; static int dy[] = { 0, 1 }; for (int di = 0; di < 2; ++di) { int nx = x + dx[di]; int ny = y + dy[di]; if (nx < 0 || nx == H || ny < 0 || ny == W) continue; int nd = d + (G[x][y] == 'k' ? x + y : 0) + 1; if (nd < dp[nx][ny]) pq.emplace(dp[nx][ny] = nd, nx, ny); } } cout << dp[H - 1][W - 1] << endl; return 0; }