結果

問題 No.663 セルオートマトンの逆操作
ユーザー 👑 horiesinitihoriesiniti
提出日時 2017-10-14 05:05:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 53,812 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 01:27:29
合計ジャッジ時間 2,125 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<iostream>
long long int MOD=1000000007;
const int LIMIT=2004;
long long int dp[2][2][2][2];
long long int nextdp[2][2][2][2];
//dp[R][L][old][now]
//next[R][L][now][next]
int as[LIMIT];

int f(int a,int b,int c){
	if((a==0)&&(b==0)&&(c==1)){
		return 1;
	}
	if((a==0)&&(b==1)&&(c==0)){
		return 1;
	}
	if((a==0)&&(b==1)&&(c==1)){
		return 1;
	}
	if((a==1)&&(b==0)&&(c==1)){
		return 1;
	}
	if((a==1)&&(b==1)&&(c==0)){
		return 1;
	}
	return 0;
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&as[i]);
	}
	
	memset(dp,0,sizeof(dp));
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				if(f(i,j,k)==as[0]){
					dp[i][j][j][k]=1;	
				}
			}
		}
	}
	long long int ans=0;
	for(int c=1;c<n;c++){
		memset(nextdp,0,sizeof(nextdp));
		for(int r=0;r<2;r++){
			for(int l=0;l<2;l++){
				for(int old=0;old<2;old++){
					for(int now=0;now<2;now++){
						int b1=as[c];
						if(c==n-2){
							int b=f(old,now,r);
							if(b==b1){
								nextdp[r][l][now][r]=(nextdp[r][l][now][r]+dp[r][l][old][now])%MOD;
							}
						}else if(c==n-1){
							if(r!=now)continue;
							int b=f(old,r,l);
							if(b==b1){
								ans=(ans+dp[r][l][old][now])%MOD;
							}
						}else{
							int b=f(old,now,0);
							if(b==b1){
								nextdp[r][l][now][0]=(nextdp[r][l][now][0]+dp[r][l][old][now])%MOD;
							}
							b=f(old,now,1);
							if(b==b1){
								nextdp[r][l][now][1]=(nextdp[r][l][now][1]+dp[r][l][old][now])%MOD;
							}
						}
					}
				}
			}
		}
		memcpy(dp,nextdp,sizeof(nextdp));
	}
	std::cout<<ans<<"\n";
}
0