結果

問題 No.584 赤、緑、青の色塗り
ユーザー 👑 kmjpkmjp
提出日時 2017-10-27 22:57:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 957 ms / 2,000 ms
コード長 1,979 bytes
コンパイル時間 1,345 ms
コンパイル使用メモリ 147,832 KB
実行使用メモリ 126,956 KB
最終ジャッジ日時 2023-08-14 04:24:02
合計ジャッジ時間 5,568 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
126,644 KB
testcase_01 AC 108 ms
126,676 KB
testcase_02 AC 108 ms
126,712 KB
testcase_03 AC 108 ms
126,956 KB
testcase_04 AC 109 ms
126,680 KB
testcase_05 AC 109 ms
126,712 KB
testcase_06 AC 108 ms
126,660 KB
testcase_07 AC 109 ms
126,688 KB
testcase_08 AC 109 ms
126,712 KB
testcase_09 AC 108 ms
126,712 KB
testcase_10 AC 109 ms
126,896 KB
testcase_11 AC 108 ms
126,660 KB
testcase_12 AC 109 ms
126,744 KB
testcase_13 AC 109 ms
126,696 KB
testcase_14 AC 113 ms
126,768 KB
testcase_15 AC 108 ms
126,752 KB
testcase_16 AC 112 ms
126,704 KB
testcase_17 AC 196 ms
126,844 KB
testcase_18 AC 119 ms
126,760 KB
testcase_19 AC 957 ms
126,736 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];
int p2[3050];

inline int mulmod(int a,int b,int mo) {
	int d,r;
	if(a==0 || b==0) return 0;
	if(a==1 || b==1) return max(a,b);
	__asm__("mull %4;"
	        "divl %2"
		: "=d" (r), "=a" (d)
		: "r" (mo), "a" (a), "d" (b));
	return r;
}

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 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;
				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;
				/*
				ll a=C[s1][r]*C[g+b][b]%mo;
				(a*=C[s2][r2]*C[r2][b2-(s2-r2)]%mo)%=mo;
				hoge += a*p2[s2]%mo;
				*/
				int a=mulmod(C[s1][r],C[g+b][b],mo);
				int c=mulmod(C[s2][r2],C[r2][b2-(s2-r2)],mo);
				hoge += mulmod(mulmod(a,c,mo),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