結果

問題 No.584 赤、緑、青の色塗り
ユーザー 👑 kmjpkmjp
提出日時 2017-10-27 22:50:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,601 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 147,380 KB
実行使用メモリ 126,988 KB
最終ジャッジ日時 2023-08-14 04:08:47
合計ジャッジ時間 6,660 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
126,708 KB
testcase_01 AC 108 ms
126,896 KB
testcase_02 AC 109 ms
126,696 KB
testcase_03 AC 109 ms
126,808 KB
testcase_04 AC 108 ms
126,720 KB
testcase_05 AC 108 ms
126,892 KB
testcase_06 AC 108 ms
126,740 KB
testcase_07 AC 108 ms
126,704 KB
testcase_08 AC 108 ms
126,744 KB
testcase_09 AC 108 ms
126,696 KB
testcase_10 AC 109 ms
126,700 KB
testcase_11 AC 109 ms
126,828 KB
testcase_12 AC 109 ms
126,732 KB
testcase_13 AC 108 ms
126,676 KB
testcase_14 AC 116 ms
126,988 KB
testcase_15 AC 109 ms
126,824 KB
testcase_16 AC 112 ms
126,736 KB
testcase_17 AC 217 ms
126,744 KB
testcase_18 AC 122 ms
126,944 KB
testcase_19 TLE -
権限があれば一括ダウンロードができます

ソースコード

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;
ll 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]=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=C[slot][s2]*C[s0+s1][s0]%mo;
		ll hoge=0;
		for(int r=0;r<=min(R,s1);r++) {
			for(int g=0;g<=G && r+g<=s1;g++) {
				int b=s1-r-g;
				if(b>B) continue;
				ll a=C[s1][r]*C[g+b][b]%mo;
				int r2=R-r;
				int g2=G-g;
				int b2=B-b;
				if((r2+b2+g2)%2) continue;
				if(r2*2>r2+b2+g2) continue;
				if(g2*2>r2+b2+g2) continue;
				if(b2*2>r2+b2+g2) continue;
				(a*=C[s2][r2]*C[r2][b2-(s2-r2)]%mo)%=mo;
				hoge += a*p2[s2]%mo;
				
			}
		}
		(ret += pat*(hoge%mo))%=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