結果

問題 No.584 赤、緑、青の色塗り
ユーザー TangentDayTangentDay
提出日時 2017-10-27 23:20:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,622 ms / 2,000 ms
コード長 2,282 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 77,448 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 04:58:02
合計ジャッジ時間 3,656 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 1000000007;
const int N = 3000;
ll fact[N], invf[N], tw[N];

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

int main() {
    fact[0] = invf[0] = tw[0] = 1;
    FOR(i,1,N-1){
        fact[i] = (fact[i-1] * i) % mod;
        invf[i] = divll(invf[i-1], i);
        tw[i] = (tw[i-1] * 2) % mod;
    }

    ll n, r, g, b;
    cin >> n >> r >> g >> b;

    ll sum = r + g + b;
    ll ans = 0;

    REP(x,n/3+2){
        int y = sum - 2*x;
        if (y < 0) continue;
        ll di = (nCr(n-2*x-y+1, x+y) * nCr(x+y, x)) % mod;
        if (di == 0) continue;
        ll tmp = 0;
        REP(rg,x+1) REP(gb,x-rg+1){
            int br = x - rg - gb;
            int rr = r - rg - br;
            int gg = g - rg - gb;
            int bb = b - gb - br;
            if (rr < 0 || gg < 0 || bb < 0) continue;
            ll saku = ((((((nCr(x, rg) * nCr(x-rg, gb) % mod) * tw[rg]) % mod) * tw[gb]) % mod) * tw[br]) % mod;
            ll hima = (nCr(y, rr) * nCr(y-rr, gg)) % mod;
            tmp = (tmp + (saku * hima) % mod) % mod;
        }
        // printf("x = %d, y = %d, di = %lld, tmp = %lld\n", x, y, di, tmp);
        tmp = (tmp * di) % mod;
        ans = (ans + tmp) % mod;
    }
    cout << ans << endl;

    return 0;
}
0