結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー chocoruskchocorusk
提出日時 2019-12-03 00:50:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 168 ms / 5,000 ms
コード長 1,586 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 111,756 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-11-28 10:08:34
合計ジャッジ時間 2,777 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[5000001], invf[5000001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int x, y, z;
	cin>>x>>y>>z;
	if(x==0 && y==0 && z==0){
	    cout<<1<<endl;
	    return 0;
	}
	fac(x+y+z+1);
	ll c=0;
	for(int i=1; i<=x+y+z; i++){
		c+=powmod(2, i)*i;
		c%=MOD;
	}
	ll ans=0;
	ll p2=powmod(2, x+y+z+1);
	for(int m=1; m<=x+y+z; m++){
		ll s=comb(m, x)*comb(m, y)%MOD*comb(m, z)%MOD*c%MOD;
		if((m+x+y+z)&1){
			ans+=MOD-s;
		}else{
			ans+=s;
		}
		ans%=MOD;
		c=(p2*comb(x+y+z+1, m+1)%MOD+MOD-2*c%MOD)%MOD;
	}
	cout<<ans*((MOD+1)/2)%MOD<<endl;
    return 0;
}
0