結果
問題 | No.1513 simple 門松列 problem |
ユーザー | wolgnik |
提出日時 | 2021-05-21 22:00:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 878 ms / 3,000 ms |
コード長 | 1,891 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 81,956 KB |
実行使用メモリ | 99,036 KB |
最終ジャッジ日時 | 2024-10-10 08:40:13 |
合計ジャッジ時間 | 6,640 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
import sys input = sys.stdin.readline N, K = map(int, input().split()) mod = 998244353 dp = [[0] * K for _ in range(K)] dp2 = [[0] * K for _ in range(K)] for i in range(K): for j in range(K): if i != j: dp[i][j] = 1 dp2[i][j] = i + j #print(dp) for _ in range(N - 2): newdp = [[0] * K for _ in range(K)] newdp2 = [[0] * K for _ in range(K)] for i in range(K): for j in range(i): newdp[j][j + 1] += dp[i][j] newdp[j][j + 1] %= mod newdp[j][i] -= dp[i][j] newdp[j][i] %= mod if i + 1 < K: newdp[j][i + 1] += dp[i][j] newdp[j][i + 1] %= mod newdp2[j][j + 1] += dp2[i][j] newdp2[j][j + 1] %= mod newdp2[j][i] -= dp2[i][j] newdp2[j][i] %= mod if i + 1 < K: newdp2[j][i + 1] += dp2[i][j] newdp2[j][i + 1] %= mod for j in range(i + 1, K): newdp[j][0] += dp[i][j] newdp[j][0] %= mod newdp[j][i] -= dp[i][j] newdp[j][i] %= mod if i + 1 < K: newdp[j][i + 1] += dp[i][j] newdp[j][i + 1] %= mod newdp[j][j] -= dp[i][j] newdp[j][j] %= mod newdp2[j][0] += dp2[i][j] newdp2[j][0] %= mod newdp2[j][i] -= dp2[i][j] newdp2[j][i] %= mod if i + 1 < K: newdp2[j][i + 1] += dp2[i][j] newdp2[j][i + 1] %= mod newdp2[j][j] -= dp2[i][j] newdp2[j][j] %= mod for i in range(K): for j in range(K - 1): newdp[i][j + 1] += newdp[i][j] newdp[i][j + 1] %= mod newdp2[i][j + 1] += newdp2[i][j] newdp2[i][j + 1] %= mod for i in range(K): for j in range(K): newdp2[i][j] += newdp[i][j] * j newdp2[i][j] %= mod dp = [a[: ] for a in newdp] dp2 = [a[: ] for a in newdp2] res1 = 0 for i in range(K): res1 += sum(dp[i]) res1 %= mod res2 = 0 for i in range(K): res2 += sum(dp2[i]) res2 %= mod print(res1, res2)