結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
chocorusk
|
| 提出日時 | 2020-09-13 10:56:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 272 ms / 5,000 ms |
| コード長 | 737 bytes |
| コンパイル時間 | 221 ms |
| コンパイル使用メモリ | 82,164 KB |
| 実行使用メモリ | 110,376 KB |
| 最終ジャッジ日時 | 2024-06-11 19:23:57 |
| 合計ジャッジ時間 | 1,178 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 |
ソースコード
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
t=int(readline())
MOD=10**9+7
MAX=2*(10**6)
f=[1]*(MAX+1)
invf=[1]*(MAX+1)
for i in range(2, MAX+1):
f[i]=f[i-1]*i%MOD
invf[MAX]=pow(f[MAX], MOD-2, MOD)
for i in range(MAX-1, -1, -1):
invf[i]=invf[i+1]*(i+1)%MOD
def comb(x, y):
if not (0<=y and y<=x):
return 0
return f[x]*invf[y]*invf[x-y]%MOD
import re
for _ in range(t):
s=readline().decode()
v=re.findall(r'\d+', s)
x, y=int(v[0]), int(v[1])
if s[0]=='C':
print(comb(x, y))
elif s[0]=='P':
print(comb(x, y)*f[y]%MOD)
else:
if y==0:
print(1)
else:
print(comb(x+y-1, y))
chocorusk