답안 #4110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4110 2013-09-01T15:13:30 Z Skeas Hexagon travel (kriii1_H) C++
1 / 1
296 ms 1900 KB
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define MOD 1000000007

int cc[2][2222];
int dp[2][4444][3][2];
int L,R,M;

inline void Plus(int &a, int b) {
	a+=b; if(a>=MOD) a-=MOD;
}
inline int move(int clr, int dir) {
	if(clr==0) return !dir?1:2;
	else if(clr==1) return !dir?2:0;
	else return !dir?0:1;
}

int main() {
#ifdef LOCAL
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d%d",&L,&R,&M);
	cc[0][0] = 1;
	int cur = 0, nxt = 1;
	for(int i=1;i<=L+R;++i) {
		memset(cc[nxt],0,sizeof(cc[nxt]));
		cc[nxt][0] = 1;
		for(int j=1;j<=2000;++j) {
			cc[nxt][j] = (cc[cur][j]+cc[cur][j-1]) % MOD;
		} swap(cur,nxt);
	}

	dp[0][0][0][0] = 1;
	cur=0,nxt=1;
	for(int i=0;i<=M;++i) {
		memset(dp[nxt],0,sizeof(dp[nxt]));
		for(int j=0;j<=L+R;++j)
		for(int k=0;k<3;++k)
		for(int h=0;h<2;++h) {
			int r = dp[cur][j][k][h];
			Plus(dp[cur][j+1][k][h^1],r);
			Plus(dp[nxt][j][move(k,h)][h],r);
		} swap(cur,nxt);
	}

	int rr=0,gg=0,bb=0;
	Plus(bb,dp[M&1][L+R][0][0]);
	Plus(bb,dp[M&1][L+R][0][1]);
	
	Plus(rr,dp[M&1][L+R][1][0]);
	Plus(rr,dp[M&1][L+R][1][1]);
	
	Plus(gg,dp[M&1][L+R][2][0]);
	Plus(gg,dp[M&1][L+R][2][1]);
	
	rr = (long long)rr * cc[(L+R)&1][L] % MOD;
	gg = (long long)gg * cc[(L+R)&1][L] % MOD;
	bb = (long long)bb * cc[(L+R)&1][L] % MOD;
	printf("%d\n",rr);
	printf("%d\n",gg);
	printf("%d\n",bb);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1900 KB Output is correct
2 Correct 0 ms 1900 KB Output is correct
3 Correct 0 ms 1900 KB Output is correct
4 Correct 0 ms 1900 KB Output is correct
5 Correct 0 ms 1900 KB Output is correct
6 Correct 12 ms 1900 KB Output is correct
7 Correct 0 ms 1900 KB Output is correct
8 Correct 12 ms 1900 KB Output is correct
9 Correct 20 ms 1900 KB Output is correct
10 Correct 296 ms 1900 KB Output is correct
11 Correct 180 ms 1900 KB Output is correct
12 Correct 100 ms 1900 KB Output is correct
13 Correct 40 ms 1900 KB Output is correct
14 Correct 100 ms 1900 KB Output is correct
15 Correct 96 ms 1900 KB Output is correct
16 Correct 36 ms 1900 KB Output is correct
17 Correct 84 ms 1900 KB Output is correct
18 Correct 100 ms 1900 KB Output is correct
19 Correct 48 ms 1900 KB Output is correct
20 Correct 64 ms 1900 KB Output is correct