結果

問題 No.1667 Forest
ユーザー 👑 KazunKazun
提出日時 2021-09-04 16:28:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 3,000 ms
コード長 670 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 76,852 KB
最終ジャッジ日時 2023-08-23 05:20:21
合計ジャッジ時間 3,705 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
76,568 KB
testcase_01 AC 123 ms
76,816 KB
testcase_02 AC 126 ms
76,692 KB
testcase_03 AC 81 ms
76,536 KB
testcase_04 AC 120 ms
76,852 KB
testcase_05 AC 109 ms
76,680 KB
testcase_06 AC 99 ms
76,668 KB
testcase_07 AC 95 ms
76,548 KB
testcase_08 AC 94 ms
76,716 KB
testcase_09 AC 84 ms
76,356 KB
testcase_10 AC 88 ms
76,720 KB
testcase_11 AC 81 ms
76,468 KB
testcase_12 AC 76 ms
71,320 KB
testcase_13 AC 74 ms
71,320 KB
testcase_14 AC 72 ms
71,368 KB
testcase_15 AC 71 ms
71,360 KB
testcase_16 AC 72 ms
71,472 KB
testcase_17 AC 72 ms
71,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Mod=map(int,input().split())

X=[]
for i in range(N+1):
    if i==0:
        X.append(0)
    elif i==1:
        X.append(1)
    else:
        X.append(pow(i,i-2,Mod))

Binom=[[0]*(N+1) for _ in range(N+1)]
for n in range(N+1):
    B=Binom[n]
    C=Binom[n-1]
    for r in range(n+1):
        if r==0 or r==n:
            B[r]=1
        else:
            B[r]=(C[r]+C[r-1])%Mod

DP=[[0]*N for _ in range(N+1)]
DP[0][0]=1

for n in range(N):
    B=Binom[N-n-1]
    D=DP[n]
    for k in range(1,N-n+1):
        alpha=(B[k-1]*X[k])%Mod
        E=DP[n+k]
        for m in range(n+1):
            E[m+k-1]+=(D[m]*alpha)%Mod
            E[m+k-1]%=Mod

print(*DP[N],sep="\n")
0