結果

問題 No.1887 K Consecutive Ks (Easy)
ユーザー miscalcmiscalc
提出日時 2022-03-06 17:24:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 477 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 134,792 KB
最終ジャッジ日時 2023-09-28 08:40:56
合計ジャッジ時間 5,032 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,108 KB
testcase_01 AC 65 ms
71,376 KB
testcase_02 AC 477 ms
134,792 KB
testcase_03 AC 64 ms
71,220 KB
testcase_04 AC 63 ms
71,148 KB
testcase_05 AC 66 ms
71,152 KB
testcase_06 AC 64 ms
71,324 KB
testcase_07 AC 70 ms
76,296 KB
testcase_08 AC 66 ms
76,220 KB
testcase_09 AC 71 ms
76,496 KB
testcase_10 AC 75 ms
76,584 KB
testcase_11 AC 124 ms
90,088 KB
testcase_12 AC 97 ms
76,596 KB
testcase_13 AC 449 ms
134,368 KB
testcase_14 AC 459 ms
134,488 KB
testcase_15 AC 463 ms
134,604 KB
testcase_16 AC 361 ms
111,684 KB
testcase_17 AC 284 ms
112,024 KB
testcase_18 AC 468 ms
134,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp = [[0 for j in range(m + 1)] for i in range(n + 1)]
for i in range(n + 1):
  dp[i][1] = 1
for j in range(1, m + 1):
  dp[0][j] = 1
for i in range(1, n + 1):
  for j in range(2, m + 1):
    dp[i][j] += dp[i][j - 1]
    dp[i][j] += dp[i - 1][m]
    if i - j >= 0:
      dp[i][j] -= dp[i - j][j - 1]
      dp[i][j] += dp[i - j][j]
      dp[i][j] -= dp[i - j][m]
    dp[i][j] %= mod

ans = (pow(m, n, mod) - (dp[n][m] - dp[n - 1][m])) % mod
print(ans)
0