結果

問題 No.1662 (ox) Alternative
ユーザー shinichishinichi
提出日時 2021-08-27 23:10:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 806 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 248,460 KB
最終ジャッジ日時 2024-05-01 04:03:05
合計ジャッジ時間 1,992 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
MOD = 10**9+7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


result = []
for t in range(T):
    A, B, C, D = map(int, input().split())
    N = A+B+C+D
    if A != B:
        result.append(0)
        continue
    ans = cmb(N, C, mod) * cmb(N-C-2, D, mod)
    ans %= MOD
    ans *= cmb(2*(A-1), A-1, mod) * pow(A, -1, mod)
    result.append(ans % MOD)
print(*result, sep='\n')

0