結果
問題 | No.2430 Damage Zone |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:02:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 195 ms / 2,000 ms |
コード長 | 1,357 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 82,772 KB |
実行使用メモリ | 94,000 KB |
最終ジャッジ日時 | 2025-03-20 21:02:13 |
合計ジャッジ時間 | 3,931 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
MOD = 998244353H, W, K = map(int, input().split())grid = [list(input().strip()) for _ in range(H)]# Initialize DP table with H rows, W columns, K damage counts (0 to K-1)dp = [[[0] * K for _ in range(W)] for __ in range(H)]# Starting cell (0,0) is '.', damage 0 has 1 wayif grid[0][0] == '.':dp[0][0][0] = 1for i in range(H):for j in range(W):if i == 0 and j == 0:continue # Already initializedif grid[i][j] == '#':continue # Skip wallscurrent = grid[i][j]for k in range(K):required_prev = -1if current == 'o':required_prev = k - 1if required_prev < 0:continue # No possible previous stateelse:required_prev = kways = 0# Check cell above (i-1, j)if i > 0 and grid[i-1][j] != '#':if 0 <= required_prev < K:ways += dp[i-1][j][required_prev]# Check cell to the left (i, j-1)if j > 0 and grid[i][j-1] != '#':if 0 <= required_prev < K:ways += dp[i][j-1][required_prev]dp[i][j][k] = ways % MOD# Sum all valid damage counts for the destinationanswer = sum(dp[H-1][W-1][k] for k in range(K)) % MODprint(answer)