結果

問題 No.663 セルオートマトンの逆操作
ユーザー IL_mstaIL_msta
提出日時 2018-03-10 00:18:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,046 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 112,424 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 05:50:06
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	//1000000007 MOD
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	
	LL ans = 0;
	LL ans0 = 0;
	LL ans1 = 0;
	LL ans2 = 0;
	for(int s=0;s<4;++s){
		//前二つ
		vector<vector<LL> > dp(N,vector<LL>(4,0));
		dp[0][s] = 1;
		for(int i=0;i<N-1;++i){
			if( A[i] == 0 ){
				dp[i+1][0] += dp[i][0];
				dp[i+1][0] += dp[i][2];
				dp[i+1][3] += dp[i][3];
			}else{//A[i]==1
				dp[i+1][1] += dp[i][0];
				dp[i+1][1] += dp[i][2];
				dp[i+1][3] += dp[i][1];

				dp[i+1][2] += dp[i][1];
				dp[i+1][2] += dp[i][3];
			}
			dp[i+1][0] %= MOD;
			dp[i+1][1] %= MOD;
			dp[i+1][2] %= MOD;
			dp[i+1][3] %= MOD;
		}
		//A[N-1]
		if( s==0 && A[N-1] == 0){
			ans += dp[N-1][0];
			ans += dp[N-1][2];
		}else if(s==1 && A[N-1] == 1){
			ans += dp[N-1][0];
			ans += dp[N-1][2];
		}else if(s==2 && A[N-1]==1){
			ans += dp[N-1][1];
			ans += dp[N-1][3];
		}else if(s==3){
			if( A[N-1] == 1 ){
				ans += dp[N-1][1];
			}else{
				ans += dp[N-1][3];
			}
		}
		ans %= MOD;
	}
	cout << ans << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()
0