結果

問題 No.1662 (ox) Alternative
コンテスト
ユーザー vjudge1
提出日時 2026-04-12 23:27:40
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 901 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,745 ms
コンパイル使用メモリ 147,960 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2026-04-12 23:27:49
合計ジャッジ時間 8,560 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
using namespace std;
#define int long long
const int N = 4e5 + 5;
const int mod = 1e9 + 7;

int a,b,c,d,fac[N],inv[N];

int qpow(int a,int b)
{
	int res = 1;
	while(b)
	{
		if(b & 1) res = res * a % mod;
		a = a * a % mod; b >>= 1;
	}
	return res;
}

int comb(int x,int y)
{
	if(x < 0 || y < 0 || x < y) return 0;
	return fac[x] * inv[y] % mod * inv[x-y] % mod;
}

signed main()
{
	fac[0] = 1; for(int i=1;i<N;i++) fac[i] = fac[i-1] * i % mod;
	inv[N-1] = qpow(fac[N-1],mod-2); for(int i=N-2;i>=0;i--) inv[i] = inv[i+1] * (i + 1) % mod;
	int ttt; cin >> ttt;
	while(ttt--)
	{
		cin >> a >> b >> c >> d;
		if(a != b) {cout << 0 << '\n'; continue;}
		if(a == 0 && b == 0)
		{
			if(d == 0) {cout << 1 << '\n'; continue;}
			else {cout << 0 << '\n'; continue;}
		}
		cout << comb(a+b+c+d,c) * qpow(a,mod-2) % mod * comb(a+d-1,a-1) % mod * comb(2*a+d,a-1) % mod << '\n';
	}
	return 0;
}
0