結果

問題 No.584 赤、緑、青の色塗り
ユーザー Lepton_sLepton_s
提出日時 2017-10-31 18:08:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,249 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 80,644 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 13:30:02
合計ジャッジ時間 1,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 3020
ll n, a[3];
ll fact[N], ifact[N];
ll inv[N];

void init(ll n = N){
    inv[1] = 1;
    for(int i = 2; i < n;i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < n; i++){
		fact[i] = (fact[i-1]*i)%mod;
		ifact[i]=(ifact[i-1]*inv[i])%mod;
	}
}

int main(){
	init();
	cin>>n; n++;
	rep(i, 3) cin>>a[i];
	sort(a, a+3); reverse(a, a+3);
	ll s = 0; rep(i, 3) s += a[i];
	ll c = 1;
	ll res = 0;
	rep(n2, s/2+1){
		ll n1 = s - n2*2;
		ll n0 = n - n1*2 - n2*3;
		ll nn = n0+n1+n2;
		ll c2 = c;
		c *= 2;
		c %= mod;
		if(n0 < 0 || n1 + n2 < a[0]) break;
		ll src = fact[nn]*ifact[n0]%mod*ifact[n1]%mod*ifact[n2]%mod*c2%mod;
		ll sr = 0;
		rep(i2, min(a[0], n2)+1){
			ll i1 = a[0]-i2;
			if(i1>n1) continue;
			ll m1 = n1-i1+i2, m2 = n2-i2;
			if(m1<0 || m2<0 || m2>a[1] || m1+m2<a[1]) continue;
			ll j2 = m2, j1 = a[1]-j2;
			ll r = fact[n1]*ifact[i1]%mod*ifact[n1-i1]%mod*fact[n2]%mod*ifact[i2]%mod*ifact[n2-i2]%mod;
			r = r*fact[m1]%mod*ifact[j1]%mod*ifact[m1-j1]%mod;
			sr += r;
		}
		sr %= mod;
		sr = sr*src%mod;
		res += sr;
	}
	res %= mod;
	cout<<res<<endl;

	return 0;
}

0