結果

問題 No.1887 K Consecutive Ks (Easy)
ユーザー 👑 rin204rin204
提出日時 2022-03-25 22:54:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 406 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 1,322 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 138,352 KB
最終ジャッジ日時 2024-04-22 07:42:57
合計ジャッジ時間 4,268 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,564 KB
testcase_01 AC 38 ms
53,012 KB
testcase_02 AC 406 ms
137,984 KB
testcase_03 AC 37 ms
51,884 KB
testcase_04 AC 37 ms
53,652 KB
testcase_05 AC 37 ms
52,008 KB
testcase_06 AC 37 ms
53,164 KB
testcase_07 AC 41 ms
59,000 KB
testcase_08 AC 45 ms
60,092 KB
testcase_09 AC 45 ms
61,260 KB
testcase_10 AC 50 ms
62,560 KB
testcase_11 AC 105 ms
89,532 KB
testcase_12 AC 71 ms
69,756 KB
testcase_13 AC 387 ms
138,008 KB
testcase_14 AC 402 ms
138,076 KB
testcase_15 AC 401 ms
138,352 KB
testcase_16 AC 318 ms
115,292 KB
testcase_17 AC 245 ms
115,092 KB
testcase_18 AC 405 ms
138,120 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