結果

問題 No.584 赤、緑、青の色塗り
ユーザー 👑 kmjpkmjp
提出日時 2017-10-27 23:13:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,451 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 147,036 KB
実行使用メモリ 126,824 KB
最終ジャッジ日時 2023-08-14 04:53:19
合計ジャッジ時間 5,161 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
126,812 KB
testcase_01 AC 109 ms
126,712 KB
testcase_02 AC 109 ms
126,732 KB
testcase_03 AC 109 ms
126,772 KB
testcase_04 AC 109 ms
126,768 KB
testcase_05 AC 109 ms
126,692 KB
testcase_06 AC 109 ms
126,792 KB
testcase_07 AC 109 ms
126,772 KB
testcase_08 AC 108 ms
126,728 KB
testcase_09 AC 109 ms
126,760 KB
testcase_10 AC 109 ms
126,824 KB
testcase_11 AC 109 ms
126,756 KB
testcase_12 AC 109 ms
126,676 KB
testcase_13 AC 108 ms
126,728 KB
testcase_14 AC 109 ms
126,712 KB
testcase_15 AC 107 ms
126,780 KB
testcase_16 AC 109 ms
126,808 KB
testcase_17 AC 109 ms
126,708 KB
testcase_18 AC 108 ms
126,668 KB
testcase_19 AC 116 ms
126,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,R,G,B,S;
int mo=1000000007;

const int CN=4001;
ll C[CN][CN];
ll p2[3050];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,CN) for(j=0;j<=i;j++) C[i][j]=(j==0||j==i)?1:(C[i-1][j-1]+C[i-1][j])%mo;
	p2[0]=1;
	FOR(i,3030) p2[i+1]=1LL*p2[i]*2%mo;
	
	cin>>N>>R>>G>>B;
	S=N-R-G-B;
	int slot=S+1;
	
	ll ret=0;
	for(int s2=0;s2<=slot;s2++) {
		int s1=R+G+B-s2*2;
		int s0=slot-s1-s2;
		if(s1<0 || s0<0) continue;
		
		ll pat=1LL*C[slot][s2]*C[s0+s1][s0]%mo;
		ll hoge=0;
		for(int r2=0;r2<=min(R,s2);r2++) {
			ll pat1=C[s2][r2];
			int r1=R-r2;
			if(r1>s1) continue;
			(pat1*=C[s1][r1])%=mo;
			int bl=B-(s2-r2);
			int gl=G-(s2-r2);
			if(bl<0 || gl<0) continue;
			(hoge += pat1*C[bl+gl][gl]%mo)%=mo;
		}
		(ret += pat*hoge%mo*p2[s2])%=mo;
	}
	
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0