結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,456 KB
testcase_01 AC 37 ms
53,256 KB
testcase_02 AC 436 ms
206,776 KB
testcase_03 AC 39 ms
54,116 KB
testcase_04 AC 39 ms
53,020 KB
testcase_05 AC 38 ms
52,212 KB
testcase_06 AC 38 ms
52,924 KB
testcase_07 AC 43 ms
58,824 KB
testcase_08 AC 46 ms
59,568 KB
testcase_09 AC 61 ms
69,920 KB
testcase_10 AC 62 ms
71,916 KB
testcase_11 AC 113 ms
93,548 KB
testcase_12 AC 97 ms
86,384 KB
testcase_13 AC 414 ms
206,800 KB
testcase_14 AC 426 ms
207,076 KB
testcase_15 AC 427 ms
206,964 KB
testcase_16 AC 347 ms
173,144 KB
testcase_17 AC 282 ms
160,620 KB
testcase_18 AC 429 ms
206,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp = [[0] * (m + 1) for _ in range(n + 1)] # dp[i][k] = # of length i array ending j meeting the conditions
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