結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-03-28 20:56:07 |
| 言語 | Python2 (2.7.18) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 950 bytes |
| コンパイル時間 | 407 ms |
| コンパイル使用メモリ | 7,040 KB |
| 実行使用メモリ | 133,596 KB |
| 最終ジャッジ日時 | 2024-07-03 22:26:14 |
| 合計ジャッジ時間 | 4,688 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
ソースコード
import re
def inv(p,q):
#return a,b where ap+bq=1
if p==1:
return (1,0)
# ap+b( xp+y )=1 , a+bx p + by = 1
b,abx=inv(q%p,p)
return abx-b*(q/p),b
mod=1000000007
frac=[1 for i in range(2000001)]
for i in range(1,2000001):
frac[i]=frac[i-1]*i
frac[i]%=mod
T=int(raw_input())
for i in range(T):
p=raw_input()
m=re.split(r'[,()]',p)
N=int(m[1])
K=int(m[2])
ans=0
if m[0]=='C'and N>=K:
ans=frac[N]
a,b=inv(frac[N-K],mod)
a%=mod
ans*=a
ans%=mod
a,b=inv(frac[K],mod)
a%=mod
ans*=a
ans%=mod
if m[0]=='P' and N>=K:
ans=frac[N]
a,b=inv(frac[N-K],mod)
a%=mod
ans*=a
ans%=mod
if m[0]=='H':
ans=frac[N+K-1]
a,b=inv(frac[K],mod)
a%=mod
ans*=a
ans%=mod
a,b=inv(frac[N-1],mod)
a%=mod
ans*=a
ans%=mod
print ans
yaoshimax