Submission

Status:

(PPPPPPPPPP)(PPPPP)(PPPPP)(PPPPPPPxSS)

Subtask/Task Score:

{20/20}{30/30}{30/30}{0/20}

Score: 80

User: devilpoohs

Problemset: กองไฟ

Language: cpp

Time: 0.301 second

Submitted On: 2026-03-06 17:40:48

#include<bits/stdc++.h>
using namespace std;
vector<string> v;
#define int long long
const int mod=1e9+7;
int fnt=0;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int aa,bb,cc;int nn;
    cin>>nn>>aa>>bb>>cc;
    int dp[nn+1][aa+1][bb+1][cc+1][3];
    //////////////////
    fnt=0;
     for(int a=0;a<=aa;a++){
        for(int b=0;b<=bb;b++){
            for(int c=0;c<=cc;c++){
                for(int tpe=0;tpe<=2;tpe++){
                    dp[0][a][b][c][tpe]=1;
                }
            }
        }
    }
                    
    for(int i=1;i<=nn;i++){
        for(int a=0;a<=aa;a++){
            for(int b=0;b<=bb;b++){
                for(int c=0;c<=cc;c++){
                    for(int tpe=0;tpe<=2;tpe++){
                        int cnt=0;
                        if(i==1){
                            if(tpe==0 and a>0){
                                if(fnt!=0){
                                    cnt+=dp[i-1][a-1][b][c][0];
                                    cnt%=mod;
                                }
                            }
                            if(tpe==1 and b>0){
                                if(fnt!=1){
                                    cnt+=dp[i-1][a][b-1][c][1];
                                    cnt%=mod;
                                }
                            }
                            if(tpe==2 and c>0){
                                if(fnt!=2){
                                    cnt+=dp[i-1][a][b][c-1][2];
                                    cnt%=mod;
                                }
                            }
                        }else{
                            if(tpe==0 and a>0){
                                cnt+=dp[i-1][a-1][b][c][1];
                                cnt%=mod;
                                cnt+=dp[i-1][a-1][b][c][2];
                                cnt%=mod;
                            }else if(tpe==1 and b>0){
                                cnt+=dp[i-1][a][b-1][c][0];
                                cnt%=mod;
                                cnt+=dp[i-1][a][b-1][c][2];
                                cnt%=mod;
                            }else if(tpe==2 and c>0){
                                cnt+=dp[i-1][a][b][c-1][0];
                                cnt%=mod;
                                cnt+=dp[i-1][a][b][c-1][1];
                                cnt%=mod;
                            }   
                        }
                        dp[i][a][b][c][tpe]=cnt;
                    }
                }
            }
        }
    }
    int ans=dp[nn][aa][bb][cc][fnt]%mod;
    ////////////////
    fnt=1;
    for(int a=0;a<=aa;a++){
        for(int b=0;b<=bb;b++){
            for(int c=0;c<=cc;c++){
                for(int tpe=0;tpe<=2;tpe++){
                    dp[0][a][b][c][tpe]=1;
                }
            }
        }
    }
                    
    for(int i=1;i<=nn;i++){
        for(int a=0;a<=aa;a++){
            for(int b=0;b<=bb;b++){
                for(int c=0;c<=cc;c++){
                    for(int tpe=0;tpe<=2;tpe++){
                        int cnt=0;
                        if(i==1){
                            if(tpe==0 and a>0){
                                if(fnt!=0){
                                    cnt+=dp[i-1][a-1][b][c][0];
                                    cnt%=mod;
                                }
                            }
                            if(tpe==1 and b>0){
                                if(fnt!=1){
                                    cnt+=dp[i-1][a][b-1][c][1];
                                    cnt%=mod;
                                }
                            }
                            if(tpe==2 and c>0){
                                if(fnt!=2){
                                    cnt+=dp[i-1][a][b][c-1][2];
                                    cnt%=mod;
                                }
                            }
                        }else{
                            if(tpe==0 and a>0){
                                cnt+=dp[i-1][a-1][b][c][1];
                                cnt%=mod;
                                cnt+=dp[i-1][a-1][b][c][2];
                                cnt%=mod;
                            }else if(tpe==1 and b>0){
                                cnt+=dp[i-1][a][b-1][c][0];
                                cnt%=mod;
                                cnt+=dp[i-1][a][b-1][c][2];
                                cnt%=mod;
                            }else if(tpe==2 and c>0){
                                cnt+=dp[i-1][a][b][c-1][0];
                                cnt%=mod;
                                cnt+=dp[i-1][a][b][c-1][1];
                                cnt%=mod;
                            }   
                        }
                        dp[i][a][b][c][tpe]=cnt;
                    }
                }
            }
        }
    }
    ans+=dp[nn][aa][bb][cc][fnt]%mod;
    
    
    //////////
    fnt=2;
    for(int a=0;a<=aa;a++){
        for(int b=0;b<=bb;b++){
            for(int c=0;c<=cc;c++){
                for(int tpe=0;tpe<=2;tpe++){
                    dp[0][a][b][c][tpe]=1;
                }
            }
        }
    }
                    
    for(int i=1;i<=nn;i++){
        for(int a=0;a<=aa;a++){
            for(int b=0;b<=bb;b++){
                for(int c=0;c<=cc;c++){
                    for(int tpe=0;tpe<=2;tpe++){
                        int cnt=0;
                        if(i==1){
                            if(tpe==0 and a>0){
                                if(fnt!=0){
                                    cnt+=dp[i-1][a-1][b][c][0];
                                    cnt%=mod;
                                }
                            }
                            if(tpe==1 and b>0){
                                if(fnt!=1){
                                    cnt+=dp[i-1][a][b-1][c][1];
                                    cnt%=mod;
                                }
                            }
                            if(tpe==2 and c>0){
                                if(fnt!=2){
                                    cnt+=dp[i-1][a][b][c-1][2];
                                    cnt%=mod;
                                }
                            }
                        }else{
                            if(tpe==0 and a>0){
                                cnt+=dp[i-1][a-1][b][c][1];
                                cnt%=mod;
                                cnt+=dp[i-1][a-1][b][c][2];
                                cnt%=mod;
                            }else if(tpe==1 and b>0){
                                cnt+=dp[i-1][a][b-1][c][0];
                                cnt%=mod;
                                cnt+=dp[i-1][a][b-1][c][2];
                                cnt%=mod;
                            }else if(tpe==2 and c>0){
                                cnt+=dp[i-1][a][b][c-1][0];
                                cnt%=mod;
                                cnt+=dp[i-1][a][b][c-1][1];
                                cnt%=mod;
                            }   
                        }
                        dp[i][a][b][c][tpe]=cnt;
                    }
                }
            }
        }
    }
    ans+=dp[nn][aa][bb][cc][fnt]%mod;
    ans%=mod;
    cout<<ans;
    return 0;
}
/*
7
3 3 1
*/