結果

問題 No.2430 Damage Zone
ユーザー nono00nono00
提出日時 2023-08-18 23:26:44
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,466 bytes
コンパイル時間 2,915 ms
コンパイル使用メモリ 256,668 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-05-06 06:11:42
合計ジャッジ時間 4,315 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,808 KB
testcase_01 AC 10 ms
6,016 KB
testcase_02 AC 28 ms
11,136 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 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 32 ms
11,648 KB
testcase_15 AC 32 ms
11,520 KB
testcase_16 AC 32 ms
11,648 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 14 ms
6,656 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 10 ms
5,888 KB
testcase_26 AC 15 ms
7,040 KB
testcase_27 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

namespace nono {

using mint = atcoder::modint998244353;

void solve() {
    int H, W, K;
    std::cin >> H >> W >> K;
    std::vector<std::string> S(H);
    for (int i = 0; i < H; i++) std::cin >> S[i];
    std::vector dp(H + 1, std::vector<std::vector<mint>>(W, std::vector<mint>(K + 1)));
    dp[0][0][K] = 1;

    auto outside = [&](int i, int j) {
        return i < 0 || j < 0 || i >= H || j >= W;
    };

    const int DI[] = {1, 0};
    const int DJ[] = {0, 1};

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            for (int k = 1; k <= K; k++) {
                for (int l = 0; l < 2; l++) {
                    int ni = i + DI[l];
                    int nj = j + DJ[l];
                    if (outside(ni, nj)) continue;
                    if (S[ni][nj] == '#') continue;
                    if (S[ni][nj] == '.') {
                        dp[ni][nj][k] += dp[i][j][k];
                    } else {
                        dp[ni][nj][k - 1] += dp[i][j][k];
                    }
                }
            }
        }
    }

    mint ans = 0;
    for (int i = 1; i <= K; i++) {
        ans += dp[H - 1][W - 1][i];
    }
    std::cout << ans.val() << std::endl;
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15);

    int t = 1;
    //  std::cin >> t;
    while (t--) nono::solve();
}
0