結果

問題 No.1662 (ox) Alternative
ユーザー googol_S0googol_S0
提出日時 2021-08-27 22:04:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 493 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 100,816 KB
最終ジャッジ日時 2024-05-01 02:38:20
合計ジャッジ時間 1,982 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
82,464 KB
testcase_01 AC 75 ms
84,060 KB
testcase_02 AC 424 ms
100,520 KB
testcase_03 AC 493 ms
100,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
def cmb(n,r):
  if r<0 or r>n:
    return 0
  return (g1[n]*g2[r]*g2[n-r])%mod
 
N=1000000
g1=[1]*(N+3)
for i in range(2,N+3):
  g1[i]=g1[i-1]*i%mod
g2=[0]*len(g1)
g2[-1]=pow(g1[-1],mod-2,mod)
for i in range(N+1,-1,-1):
  g2[i]=g2[i+1]*(i+1)%mod
inv=[0]*(N+3)
for i in range(1,N+3):
  inv[i]=g2[i]*g1[i-1]%mod
for t in range(int(input())):
  A,B,C,D=map(int,input().split())
  if A!=B:
    print(0)
    continue
  if A+B+C+D==C:
    print(1)
    continue
  X=cmb(A+B+C+D,C)
  D+=A+2
  print(X*cmb(D+A-2,A-1)*cmb(D-3,A-1)*pow(A,mod-2,mod)%mod)
0