結果

問題 No.1887 K Consecutive Ks (Easy)
ユーザー mkawa2mkawa2
提出日時 2022-03-26 00:31:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 643 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 137,984 KB
最終ジャッジ日時 2024-04-22 09:42:31
合計ジャッジ時間 5,525 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,224 KB
testcase_01 AC 38 ms
52,480 KB
testcase_02 AC 637 ms
137,928 KB
testcase_03 AC 38 ms
52,224 KB
testcase_04 AC 37 ms
52,224 KB
testcase_05 AC 38 ms
52,608 KB
testcase_06 AC 38 ms
52,352 KB
testcase_07 AC 46 ms
60,532 KB
testcase_08 AC 51 ms
62,464 KB
testcase_09 AC 46 ms
60,672 KB
testcase_10 AC 48 ms
61,696 KB
testcase_11 AC 143 ms
89,728 KB
testcase_12 AC 73 ms
67,584 KB
testcase_13 AC 599 ms
137,984 KB
testcase_14 AC 630 ms
137,984 KB
testcase_15 AC 635 ms
137,856 KB
testcase_16 AC 408 ms
115,072 KB
testcase_17 AC 421 ms
115,072 KB
testcase_18 AC 643 ms
137,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = (1<<63)-1
inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

n, m = LI()
ss = [[0]*(n+2) for _ in range(m+1)]
dp = [0]*(n+2)
dp[1] = 1

for i in range(n):
    for a in range(1, m+1):
        l = max(i+2-a, 0)
        val = dp[i+1]-dp[l]-(ss[a][i+1]-ss[a][l])
        val %= md
        ss[a][i+2] = (ss[a][i+1]+val)%md
        dp[i+2] += val
        dp[i+2] %= md
    dp[i+2] = (dp[i+2]+dp[i+1])%md

ans = pow(m, n, md)-(dp[n+1]-dp[n])

print(ans%md)
0