結果
| 問題 | No.584 赤、緑、青の色塗り | 
| コンテスト | |
| ユーザー |  nmnmnmnmnmnmnm | 
| 提出日時 | 2017-09-09 16:07:45 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 36 ms / 2,000 ms | 
| コード長 | 2,453 bytes | 
| コンパイル時間 | 2,054 ms | 
| コンパイル使用メモリ | 87,592 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-21 20:46:44 | 
| 合計ジャッジ時間 | 2,069 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | AC * 14 | 
ソースコード
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
#define MOD 1000000007
#define N_MAX 100000
long long fact[N_MAX];
long long rfact[N_MAX];
long long modpow(long long a, long long b){ 
  long long r = 1LL;
  while(b){
    if(b & 1LL)r *= a;
    if(r >= MOD)r %= MOD;
    a *= a;
    if(a >= MOD)a %= MOD;
    b >>= 1LL;
  }
  return r;
}
long long nCr(long long n, long long r){ 
  long long ret = 1LL;
  ret *= fact[n];
  ret %= MOD;
  ret *= rfact[r];
  ret %= MOD;
  ret *= rfact[n-r];
  ret %= MOD;
  return ret;
}
int main() {
  clr(fact,0);
  fact[0]=1;
  rep(i,1,N_MAX){
    fact[i] = fact[i-1]*i;
    fact[i] %= MOD;
  }
  clr(rfact,0);
  rfact[0]=1;
  rep(i,1,N_MAX){
    rfact[i] = rfact[i-1]*modpow(i,MOD-2);
    rfact[i] %= MOD;
  }
  ll ans = 0;
  ll n,r,g,b;
  cin>>n>>r>>g>>b;
  if(n<1||3000<n){
    cout << -1 << endl;
    return 0;
  }
  if(r<0||3000<r||g<0||3000<g||b<0||3000<b){
    cout << -1 << endl;
    return 0;
  }  
  rep(i,0,n+1){
    ll two = i;
    ll one = r+g+b-two*2;
    if(one<0)continue;
    ll n1 = n-(two*2+one)-(two+one-1);
    if(n1<0)continue;
    ll ans1 = nCr(two+one,one);
    ans1 *= modpow(2,two);
    ans1 %= MOD;
    ans1 *= nCr(n1+two+one,two+one);
    ans1 %= MOD;
    rep(j,0,two+1){
      ll ans2 = ans1;
      ll r1 = r-j;
      ll g1 = g-(two-j);
      ll b1 = b-(two-j);
      ll one1 = one;
      if(r1<0||g1<0||b1<0)continue;
      if(r1>one1)continue;
      ans2 *= nCr(two,j);
      ans2 %= MOD;
      ans2 *= nCr(one1,r1);
      ans2 %= MOD;
      one1 -= r1;
      one1 += j;
      if(g1+b1!=one1)continue;
      ans2 *= nCr(one1,g1);
      ans2 %= MOD;
      one1 -= g1;
      ans2 *= nCr(one1,b1);
      ans2 %= MOD;
      ans += ans2;
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
            
            
            
        