結果

問題 No.2528 pop_(backfront or not)
ユーザー nikoro256nikoro256
提出日時 2023-11-03 22:35:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 791 ms / 2,000 ms
コード長 954 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 81,856 KB
実行使用メモリ 107,988 KB
最終ジャッジ日時 2023-11-03 22:35:54
合計ジャッジ時間 6,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
59,640 KB
testcase_01 AC 37 ms
59,640 KB
testcase_02 AC 37 ms
59,640 KB
testcase_03 AC 38 ms
59,640 KB
testcase_04 AC 38 ms
59,640 KB
testcase_05 AC 55 ms
70,524 KB
testcase_06 AC 68 ms
76,172 KB
testcase_07 AC 86 ms
76,488 KB
testcase_08 AC 87 ms
76,700 KB
testcase_09 AC 135 ms
78,864 KB
testcase_10 AC 270 ms
84,604 KB
testcase_11 AC 261 ms
85,080 KB
testcase_12 AC 342 ms
88,440 KB
testcase_13 AC 393 ms
89,832 KB
testcase_14 AC 430 ms
92,800 KB
testcase_15 AC 626 ms
102,040 KB
testcase_16 AC 761 ms
107,968 KB
testcase_17 AC 765 ms
107,968 KB
testcase_18 AC 791 ms
107,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p=998244353
N = 4000  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用S
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

N=int(input())
dp=[[0 for _ in range(2*i+1)] for i in range(N+1)]
#後ろから遡る。dp[残った個数(2*i+1)][何番目の数字]
dp[0][0]=1
p=998244353
for i in range(N):
    for j in range(2*i+1):
        count=2*i+1
        dp[i+1][j+2]+=dp[i][j]*(cmb(j,2,p)+j)
        dp[i+1][j+2]%=p
        dp[i+1][j+1]+=dp[i][j]*(1+j*(count-j-1))
        dp[i+1][j+1]%=p
        dp[i+1][j]+=dp[i][j]*(cmb(count-j-1,2,p)+count-j-1)
        dp[i+1][j]%=p
for d in dp[-1]:
    print(d)
0