結果

問題 No.1662 (ox) Alternative
コンテスト
ユーザー vjudge1
提出日時 2025-11-17 22:22:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 195,896 KB
実行使用メモリ 11,468 KB
最終ジャッジ日時 2025-11-17 22:22:17
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define lowbit(x) x&(-x)
using namespace std;
const int mod=1e9+7;
int t,a,b,c,d,jie[500005],inv[500005];
int qpow(int a,int b=mod-2){
    int ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod,b>>=1;
    }
    return ans;
}
int C(int n,int m){if(n<m||n<0||m<0)return 0;return jie[n]*inv[m]%mod*inv[n-m]%mod;}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    jie[0]=inv[0]=1;
    for(int i=1;i<=500000;i++)jie[i]=jie[i-1]*i%mod;
    inv[500000]=qpow(jie[500000]);
    for(int i=499999;i;i--)inv[i]=inv[i+1]*(i+1)%mod;
    cin>>t;
    while(t--){
        cin>>a>>b>>c>>d;
        if(a!=b)cout<<"0\n";
        else if(!a){
            if(d)cout<<"0\n";
            else cout<<"1\n";
        }
        else cout<<C(a+b+c+d,c)*inv[a]%mod*inv[d]%mod*(a*jie[max(a+d-1,0ll)]%mod*C(a+b+d-1,a+d)%mod-jie[a+d]*C(a+b+d-1,a+d+1)%mod+mod)%mod<<'\n';
    }
    return 0;
}
0