結果

問題 No.584 赤、緑、青の色塗り
ユーザー momoyuumomoyuu
提出日時 2023-03-11 18:59:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 3,790 bytes
コンパイル時間 2,898 ms
コンパイル使用メモリ 251,716 KB
実行使用メモリ 74,104 KB
最終ジャッジ日時 2023-10-18 10:12:53
合計ジャッジ時間 4,149 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 24 ms
29,264 KB
testcase_15 AC 53 ms
63,528 KB
testcase_16 AC 62 ms
73,892 KB
testcase_17 AC 63 ms
74,008 KB
testcase_18 AC 62 ms
74,104 KB
testcase_19 AC 72 ms
74,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class t> using vc = vector<t>;
template<class t> using vvc = vc<vc<t>>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vc<int>;
using vvi = vvc<int>;
using vl = vc<ll>;
using vvl = vvc<ll>;

#define rep(i,a,b) for (int i = (int)(a); i < (int)(b); i++)
#define irep(i,a,b) for (int i = (int)(a); i > (int)(b); i--)
#define all(a) a.begin(),a.end()
#define print(n) cout << n << '\n'
#define pritn(n) print(n)
#define printv(n,a) {copy(all(n),ostream_iterator<a>(cout," ")); cout<<"\n";}
#define printvv(n,a) {for(auto itr:n) printv(itr,a);}
#define rup(a,b) (a+b-1)/b
#define input(A,N) rep(i,0,N) cin>>A[i]
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)



//const ll mod = 998'244'353;
const ll mod = 1'000'000'007;
//const ll mod = 67'280'421'310'721;
struct mint{
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const{
        return mint(-x);
    }
    mint& operator+=(const mint& a){
        if((x+=a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator-=(const mint& a){
        if((x+=mod-a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator*=(const  mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    mint pow(long long n) const {
        assert(0 <= n);
        mint a = *this, r = 1;
        while (n) {
            if (n & 1) r *= a;
            a *= a;
            n >>= 1;
        }
        return r;
    }
    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint& a){
        return (*this)*=a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    bool operator==(const mint& a) const {
        return x == a.x;
    }
    bool operator<(const mint& a) const{
        return x < a.x;
    }
};

int n,r,g,b;

int main(){
    cout << fixed << setprecision(15);
    
    cin>>n>>r>>g>>b;
    vvc<mint> comb(n+1,vc<mint>(n+1,1));
    if(r+g+b>n){
        print(0);
        return 0;
    }
    if(n==1){
        print(1);
        return 0;
    }
    for(int i = 0;i<=n;i++) comb[i][i] = comb[i][0] = mint(1);
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<i;j++){
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
        }
    }
    vc<mint> d(n+1,0);
    mint ans = 0;
    for(int i = 0;i<=n;i++){
        if(2*i>r+g+b) break;
        for(int j = 0;j<=min(i,r);j++){
            int rest = i - j;
            if(rest>min(g,b)) continue;
            if(2*rest+j>g+b) continue;
            int rg = g - rest;
            int rb = b - rest;
            //1マスの数
            //int want = (r-i) + rg + rb;

            mint tmp = 1;
            int ri = r + g + b - 2*i;
            int want = ri;
            int need = 2 * want + 3 * i - 1;
            //cout<<i<<" "<<j<<" "<<want<<need<<endl;
            if(need>n) continue;
            int can = n - need;
            tmp *= comb[i][j];
            tmp *= comb[can+i+want][can];
            tmp *= comb[i+want][i];
            tmp *= mint(2).pow(i);
            tmp *= comb[want][r-j];
            tmp *= comb[rg+rb][rg];
            ans += tmp;
           // cout<<i<<" "<<j<<" "<<ans<<" "<<want<<" "<<need<<endl;
        }
    }
    print(ans);

    
    //system("pause");
    return 0;
}
0