結果
問題 |
No.1127 変形パスカルの三角形
|
ユーザー |
![]() |
提出日時 | 2020-07-26 20:45:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 617 ms / 1,500 ms |
コード長 | 599 bytes |
コンパイル時間 | 93 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 42,240 KB |
最終ジャッジ日時 | 2024-06-28 19:22:01 |
合計ジャッジ時間 | 17,912 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
import sys input=lambda: sys.stdin.readline().rstrip() mod=10**9+7 a,b=map(int,input().split()) n,k=map(int,input().split()) a%=mod b%=mod n_max=4*(10**5+1) F,FI=[0]*(n_max+1),[0]*(n_max+1) F[0],FI[0]=1,1 for i in range(n_max): F[i+1]=(F[i]*(i+1))%mod FI[n_max-1]=pow(F[n_max-1],mod-2,mod) for i in reversed(range(n_max-1)): FI[i]=(FI[i+1]*(i+1))%mod def comb(x,y): return (F[x]*FI[x-y]*FI[y])%mod if k==1: print(a%mod) else: print((a*comb(n-1,k-1)+b*comb(n-1,k-2))%mod) ans=((a**2+b**2)*comb(2*(n-1),n-1))%mod for i in range(n-1): ans=(ans+2*a*b*comb(n-1,i)*comb(n-1,i+1))%mod print(ans)