結果
問題 | No.117 組み合わせの数 |
ユーザー |
![]() |
提出日時 | 2020-01-20 22:34:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,992 ms / 5,000 ms |
コード長 | 1,511 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 167,680 KB |
最終ジャッジ日時 | 2024-07-02 23:12:55 |
合計ジャッジ時間 | 4,565 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 |
ソースコード
import syssys.setrecursionlimit(10 ** 6)from bisect import *from collections import *from heapq import *int1 = lambda x: int(x) - 1p2D = lambda x: print(*x, sep="\n")def II(): return int(sys.stdin.readline())def MI(): return map(int, sys.stdin.readline().split())def MI1(): return map(int1, sys.stdin.readline().split())def MF(): return map(float, sys.stdin.readline().split())def LI(): return list(map(int, sys.stdin.readline().split()))def LI1(): return list(map(int1, sys.stdin.readline().split()))def LF(): return list(map(float, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]def nCr(com_n, com_r):if com_n < com_r: return 0return fac[com_n] * ifac[com_r] * ifac[com_n - com_r] % mddef nPr(com_n, com_r):if com_n < com_r: return 0return fac[com_n] * ifac[com_n - com_r] % mddef nHr(com_n, com_r):if (com_n, com_r)==(0,0):return 1return nCr(com_n + com_r - 1, com_r)md = 10 ** 9 + 7n_max = 10 ** 6 * 2fac = [1]for i in range(1, n_max + 1): fac.append(fac[-1] * i % md)ifac = [1] * (n_max + 1)ifac[n_max] = pow(fac[n_max], md - 2, md)for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1) % mddef main():t = II()for _ in range(t):s = input()op = s[0]n, r = map(int, s[2:-1].split(","))if op == "C": print(nCr(n, r))if op == "P": print(nPr(n, r))if op == "H": print(nHr(n, r))main()