結果

問題 No.1662 (ox) Alternative
ユーザー Shaojia
提出日時 2025-02-16 21:11:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 2,335 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 212,180 KB
実行使用メモリ 6,816 KB
最終ジャッジ日時 2025-02-16 21:11:26
合計ジャッジ時間 3,085 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define rep(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii<=Ii##_;Ii++)
#define per(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii>=Ii##_;Ii--)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double db;
#define fir first
#define sec second
#define siz(Aa) ((int)(Aa).size())
#define all(Aa) (Aa).begin(),(Aa).end()
#define ckmx(Aa,Bb) (Aa=max(Aa,Bb))
#define ckmn(Aa,Bb) (Aa=min(Aa,Bb))
template<int P>
struct mod_int{
	using Z=mod_int;
	static signed mo(signed x){return x<0?x+P:x;}
	signed x;
	signed val()const{return x;}
	mod_int():x(0){}
	template<class T>mod_int(const T&x_):x(x_>=0&&x_<P?static_cast<signed>(x_):mo(static_cast<signed>(x_%P))){}
	bool operator==(const Z&rhs)const{return x==rhs.x;}
	bool operator!=(const Z&rhs)const{return x!=rhs.x;}
	Z operator-()const{return Z(x?P-x:0);}
	Z pow(long long k)const{Z res=1,t=*this;while(k){if(k&1)res*=t;if(k>>=1)t*=t;}return res;}
	Z operator~()const{assert(x);return pow(P-2);}
	Z&operator++(){x<P-1?++x:x=0;return *this;}
	Z&operator--(){x?--x:x=P-1;return *this;}
	Z operator++(signed){Z ret=x;x<P-1?++x:x=0;return ret;}
	Z operator--(signed){Z ret=x;x?--x:x=P-1;return ret;}
	Z&operator+=(const Z&rhs){(x+=rhs.x)>=P&&(x-=P);return *this;}
	Z&operator-=(const Z&rhs){(x-=rhs.x)<0&&(x+=P);return *this;}
	Z&operator*=(const Z&rhs){x=1ULL*x*rhs.x%P;return *this;}
	Z&operator/=(const Z&rhs){return *this*=~rhs;}
#define setO(o) friend Z operator o(const Z&lhs,const Z&rhs){Z res=lhs;return res o##=rhs;}
	setO(+)setO(-)setO(*)setO(/)
#undef setO
	friend istream& operator>>(istream&is,Z&x){long long y;is>>y;x=Z(y);return is;}
	friend ostream& operator<<(ostream&os,const Z&x){return os<<x.val();}
};
const int P=1e9+7;
using Z=mod_int<P>;
const int N=4e5+10;
Z fac[N],ivf[N];
Z bin(int x,int y){
	return fac[x]*ivf[y]*ivf[x-y];
}
void work(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a!=b){
		cout<<"0\n";
	}else if(a==0){
		if(d>0){
			cout<<"0\n";
		}else{
			cout<<"1\n";
		}
	}else{
		cout<<ivf[a]*fac[a-1]*bin(a+d-1,a-1)*bin(2*a+d,a-1)*bin(a+b+c+d,c)<<"\n";
	}
}
signed main(){ios::sync_with_stdio(false),cin.tie(nullptr);
	fac[0]=1;
	rep(i,1,N-1) fac[i]=fac[i-1]*i;
	ivf[N-1]=~fac[N-1];
	per(i,N-1,1) ivf[i-1]=ivf[i]*i;
	int T;cin>>T;
	while(T--)work();
return 0;}
/*
*/
0