結果
問題 | No.1513 simple 門松列 problem |
ユーザー | tamato |
提出日時 | 2021-05-21 23:11:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 553 ms / 3,000 ms |
コード長 | 2,790 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 82,492 KB |
実行使用メモリ | 326,956 KB |
最終ジャッジ日時 | 2024-10-10 10:05:59 |
合計ジャッジ時間 | 4,577 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,956 KB |
testcase_01 | AC | 39 ms
53,356 KB |
testcase_02 | AC | 553 ms
326,956 KB |
testcase_03 | AC | 42 ms
55,988 KB |
testcase_04 | AC | 39 ms
53,992 KB |
testcase_05 | AC | 42 ms
55,620 KB |
testcase_06 | AC | 42 ms
57,284 KB |
testcase_07 | AC | 40 ms
54,896 KB |
testcase_08 | AC | 87 ms
77,408 KB |
testcase_09 | AC | 38 ms
54,592 KB |
testcase_10 | AC | 39 ms
53,268 KB |
testcase_11 | AC | 37 ms
53,600 KB |
testcase_12 | AC | 38 ms
53,696 KB |
testcase_13 | AC | 38 ms
54,916 KB |
testcase_14 | AC | 542 ms
323,684 KB |
testcase_15 | AC | 549 ms
324,408 KB |
testcase_16 | AC | 543 ms
325,900 KB |
testcase_17 | AC | 365 ms
232,204 KB |
testcase_18 | AC | 187 ms
128,936 KB |
testcase_19 | AC | 90 ms
78,448 KB |
testcase_20 | AC | 148 ms
104,440 KB |
ソースコード
mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, K = map(int, input().split()) dp1 = [[0] * (K*K) for _ in range(N)] dp2 = [[0] * (K*K) for _ in range(N)] for k1 in range(K): for k2 in range(k1): dp1[1][k1*K+k2] = 1 dp2[1][k1*K+k2] = k1+k2 for i in range(2, N): if not i&1: for k2 in range(K): S1 = 0 S2 = 0 for k1 in range(K-1, k2, -1): S1 = (S1 + dp1[i-1][k1*K+k2])%mod S2 = (S2 + dp2[i-1][k1*K+k2])%mod for k3 in range(k2+1, K): dp1[i][k2*K+k3] = (S1 - dp1[i-1][k3*K+k2])%mod dp2[i][k2*K+k3] = ((S2 - dp2[i-1][k3*K+k2])%mod + (k3 * dp1[i][k2*K+k3])%mod)%mod else: for k2 in range(K): S1 = 0 S2 = 0 for k1 in range(k2): S1 = (S1 + dp1[i-1][k1*K+k2])%mod S2 = (S2 + dp2[i-1][k1*K+k2])%mod for k3 in range(k2): dp1[i][k2*K+k3] = (S1 - dp1[i-1][k3*K+k2])%mod dp2[i][k2*K+k3] = ((S2 - dp2[i-1][k3*K+k2])%mod + (k3 * dp1[i][k2*K+k3])%mod)%mod ans1 = ans2 = 0 for k1 in range(K): for k2 in range(K): ans1 = (ans1 + dp1[-1][k1*K+k2])%mod ans2 = (ans2 + dp2[-1][k1*K+k2])%mod dp1 = [[0] * (K*K) for _ in range(N)] dp2 = [[0] * (K*K) for _ in range(N)] for k1 in range(K): for k2 in range(k1 + 1, K): dp1[1][k1*K+k2] = 1 dp2[1][k1*K+k2] = k1+k2 for i in range(2, N): if i&1: for k2 in range(K): S1 = 0 S2 = 0 for k1 in range(K-1, k2, -1): S1 = (S1 + dp1[i-1][k1*K+k2])%mod S2 = (S2 + dp2[i-1][k1*K+k2])%mod for k3 in range(k2+1, K): dp1[i][k2*K+k3] = (S1 - dp1[i-1][k3*K+k2])%mod dp2[i][k2*K+k3] = ((S2 - dp2[i-1][k3*K+k2])%mod + (k3 * dp1[i][k2*K+k3])%mod)%mod else: for k2 in range(K): S1 = 0 S2 = 0 for k1 in range(k2): S1 = (S1 + dp1[i-1][k1*K+k2])%mod S2 = (S2 + dp2[i-1][k1*K+k2])%mod for k3 in range(k2): dp1[i][k2*K+k3] = (S1 - dp1[i-1][k3*K+k2])%mod dp2[i][k2*K+k3] = ((S2 - dp2[i-1][k3*K+k2])%mod + (k3 * dp1[i][k2*K+k3])%mod)%mod for k1 in range(K): for k2 in range(K): ans1 = (ans1 + dp1[-1][k1*K+k2])%mod ans2 = (ans2 + dp2[-1][k1*K+k2])%mod print(ans1, ans2) if __name__ == '__main__': main()