結果

問題 No.2003 Frog on Grid
ユーザー to-omerto-omer
提出日時 2022-01-31 18:28:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 112,384 KB
最終ジャッジ日時 2023-09-10 17:05:29
合計ジャッジ時間 5,309 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,088 KB
testcase_01 AC 76 ms
71,212 KB
testcase_02 AC 75 ms
71,104 KB
testcase_03 AC 75 ms
71,256 KB
testcase_04 AC 75 ms
71,284 KB
testcase_05 AC 78 ms
71,412 KB
testcase_06 AC 76 ms
71,336 KB
testcase_07 AC 75 ms
71,408 KB
testcase_08 AC 76 ms
71,312 KB
testcase_09 AC 90 ms
76,568 KB
testcase_10 AC 86 ms
75,832 KB
testcase_11 AC 88 ms
76,208 KB
testcase_12 AC 94 ms
76,064 KB
testcase_13 AC 89 ms
76,124 KB
testcase_14 AC 89 ms
76,180 KB
testcase_15 AC 91 ms
76,116 KB
testcase_16 AC 84 ms
76,000 KB
testcase_17 AC 166 ms
86,840 KB
testcase_18 AC 221 ms
105,112 KB
testcase_19 AC 139 ms
112,384 KB
testcase_20 AC 167 ms
109,872 KB
testcase_21 AC 120 ms
112,004 KB
testcase_22 AC 135 ms
109,696 KB
testcase_23 AC 170 ms
105,740 KB
testcase_24 AC 185 ms
104,828 KB
testcase_25 AC 146 ms
104,656 KB
testcase_26 AC 139 ms
104,688 KB
testcase_27 AC 191 ms
105,228 KB
testcase_28 AC 142 ms
104,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353


def main():
    H, W, K, C = open(0).read().split(maxsplit=3)
    H, W, K = int(H), int(W), int(K)
    dp = [0] * (H * W)
    stair = [0] * (H * W)
    dacc = [0] * (H * W)
    for i in range(H):
        hacc = [0] * W
        for j in range(W):
            x = 0
            if i == 0 and j == 0:
                dp[0] += 1
            else:
                if i > 0:
                    x += stair[(i - 1) * W + j]
                if j > 0:
                    x += hacc[j - 1]
                if j >= K + 1:
                    x -= hacc[j - K - 1]
                p = max(0, K - j)
                if i >= p + 1:
                    x -= dacc[(i - p - 1) * W + j + p - K]
                if i >= K + 2 and j + 1 < W:
                    x += dacc[(i - K - 2) * W + j + 1]
                x %= MOD
                if C[i * (W + 1) + j] == ".":
                    dp[i * W + j] = x

            stair[i * W + j] = (x + dp[i * W + j]) % MOD
            dacc[i * W + j] = dp[i * W + j]
            if i > 0 and j + 1 < W:
                dacc[i * W + j] = (dacc[i * W + j] + dacc[(i - 1) * W + j + 1]) % MOD
            hacc[j] = dp[i * W + j]
            if j > 0:
                hacc[j] = (hacc[j] + hacc[j - 1]) % MOD

    print(dp[-1])


if __name__ == "__main__":
    main()
0