結果

問題 No.2917 二重木
ユーザー vwxyz
提出日時 2024-10-04 22:53:37
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 776 ms / 3,000 ms
コード長 524 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 49,920 KB
最終ジャッジ日時 2024-10-04 22:53:47
合計ジャッジ時間 8,428 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

N,P=map(int,input().split())
ans=0
bino=[[0]*(N+1) for x in range(N+1)]
bino[0][0]=1
for x in range(N+1):
    for y in range(N+1):
        if y:
            bino[x][y]+=bino[x][y-1]
        if x:
            bino[x][y]+=bino[x-1][y]
        bino[x][y]%=P
def comb(n,k):
    if k<0:
        return 0
    if n<k:
        return 0
    return bino[k][n-k]
ans=0
for c in range(1,N+1):
    if c==1:
        cnt=1
    else:
        cnt=pow(c,c-2,P)
    cnt*=comb(N-1,c-1)*pow(N,N-c,P)
    cnt%=P
    ans+=cnt
    ans%=P
print(ans)
0