結果

問題 No.1887 K Consecutive Ks (Easy)
ユーザー iorioniorion
提出日時 2022-03-25 23:49:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 617 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,348 KB
実行使用メモリ 207,016 KB
最終ジャッジ日時 2024-04-22 08:52:30
合計ジャッジ時間 4,526 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,308 KB
testcase_01 AC 39 ms
52,000 KB
testcase_02 AC 434 ms
207,016 KB
testcase_03 AC 38 ms
52,244 KB
testcase_04 AC 39 ms
52,700 KB
testcase_05 AC 38 ms
52,276 KB
testcase_06 AC 38 ms
52,800 KB
testcase_07 AC 43 ms
59,312 KB
testcase_08 AC 44 ms
59,416 KB
testcase_09 AC 61 ms
70,736 KB
testcase_10 AC 62 ms
71,892 KB
testcase_11 AC 114 ms
93,208 KB
testcase_12 AC 96 ms
86,236 KB
testcase_13 AC 416 ms
206,880 KB
testcase_14 AC 423 ms
206,952 KB
testcase_15 AC 422 ms
206,936 KB
testcase_16 AC 349 ms
173,204 KB
testcase_17 AC 279 ms
161,020 KB
testcase_18 AC 429 ms
206,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
n, m = map(int, input().split())

dp = [[0] * (m + 1) for _ in range(n + 1)] # dp[i] = # of array meeting the conditions ending i
no = [[0] * (m + 1) for _ in range(n + 1)] # no[i][j] = # of length i array ending j not meeting the conditions
no[0][0] = 1

for i in range(n):
    no_sum = sum(no[i]) % MOD
    for k in range(1, min(m + 1, n - i + 1)):
        dp[i + k][k] = (dp[i + k][k] + no_sum - no[i][k]) % MOD
    for k in range(2, m + 1):
        no[i + 1][k] = (no_sum - dp[i + 1][k]) % MOD

ans = 0
for i in range(1, n + 1):
    ans += sum(dp[i]) * pow(m, n - i, MOD)
    ans %= MOD
print(ans)
0