結果

問題 No.1887 K Consecutive Ks (Easy)
ユーザー 👑 rin204rin204
提出日時 2022-03-25 22:54:43
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 445 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 137,704 KB
最終ジャッジ日時 2023-08-04 09:59:50
合計ジャッジ時間 5,184 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,616 KB
testcase_01 AC 74 ms
71,400 KB
testcase_02 AC 445 ms
137,592 KB
testcase_03 AC 73 ms
71,364 KB
testcase_04 AC 72 ms
71,348 KB
testcase_05 AC 72 ms
71,540 KB
testcase_06 AC 75 ms
71,444 KB
testcase_07 AC 78 ms
76,200 KB
testcase_08 AC 81 ms
76,252 KB
testcase_09 AC 79 ms
76,440 KB
testcase_10 AC 85 ms
76,620 KB
testcase_11 AC 137 ms
90,676 KB
testcase_12 AC 107 ms
76,664 KB
testcase_13 AC 415 ms
137,704 KB
testcase_14 AC 432 ms
137,616 KB
testcase_15 AC 434 ms
137,568 KB
testcase_16 AC 349 ms
114,360 KB
testcase_17 AC 277 ms
114,560 KB
testcase_18 AC 438 ms
137,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

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

dp = [[0] * (m + 1) for _ in range(n + 1)]
dp[0][0] = 1
tot = [0] * (n + 1)
tot[0] = 1
powm = [1]
for _ in range(n):
    powm.append(powm[-1] * m % MOD)

ans = 0
for i in range(1, n + 1):
    ans += tot[i - 1] * powm[n - i]
    ans %= MOD
    for j in range(2, m + 1):
        dp[i][j] = tot[i - 1]
        if i >= j:
            dp[i][j] -= tot[i - j] - dp[i - j][j]
            ans += (tot[i - j] - dp[i - j][j]) * powm[n - i]
            ans %= MOD
        dp[i][j] %= MOD
        tot[i] += dp[i][j]
        tot[i] %= MOD

print(ans)
0