結果

問題 No.2430 Damage Zone
コンテスト
ユーザー a01sa01to
提出日時 2025-10-17 02:11:28
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,331 bytes
コンパイル時間 3,802 ms
コンパイル使用メモリ 302,392 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2025-10-17 02:11:34
合計ジャッジ時間 5,133 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

#include <atcoder/modint>
using mint = atcoder::modint998244353;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int h, w, k;
  cin >> h >> w >> k;
  vector Grid(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> Grid[i][j];
  queue<tuple<int, int, int>> q;
  vector dp(h, vector(w, vector<mint>(k, 0)));
  vector added(h, vector(w, vector<bool>(k, false)));
  dp[0][0][0] = 1;
  q.push({ 0, 0, 0 });
  while (!q.empty()) {
    auto [x, y, hp] = q.front();
    q.pop();
    if (x + 1 < h) {
      if (Grid[x + 1][y] != '#') {
        int nhp = hp + (Grid[x + 1][y] == 'o');
        if (nhp < k) {
          dp[x + 1][y][nhp] += dp[x][y][hp];
          if (!added[x + 1][y][nhp]) q.push({ x + 1, y, nhp });
          added[x + 1][y][nhp] = true;
        }
      }
    }
    if (y + 1 < w) {
      if (Grid[x][y + 1] != '#') {
        int nhp = hp + (Grid[x][y + 1] == 'o');
        if (nhp < k) {
          dp[x][y + 1][nhp] += dp[x][y][hp];
          if (!added[x][y + 1][nhp]) q.push({ x, y + 1, nhp });
          added[x][y + 1][nhp] = true;
        }
      }
    }
  }
  mint ans = 0;
  rep(i, k) ans += dp[h - 1][w - 1][i];
  cout << ans.val() << '\n';
  return 0;
}
0