結果

問題 No.117 組み合わせの数
コンテスト
ユーザー chocorusk
提出日時 2020-09-13 10:55:15
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 2,831 ms / 5,000 ms
コード長 737 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 727 ms
コンパイル使用メモリ 20,956 KB
実行使用メモリ 171,480 KB
最終ジャッジ日時 2026-03-05 01:24:03
合計ジャッジ時間 7,695 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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))
0