結果

問題 No.663 セルオートマトンの逆操作
ユーザー ldsybldsyb
提出日時 2018-03-09 22:56:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 164,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 17:45:49
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 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 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int64_t n, mod = 1000000007;
	cin >> n;
	int64_t a[n], now[] = {0, 0, 1, 1, 0, 0, 1, 1}, prev[] = {0, 0, 0, 0, 1, 1, 1, 1}, next[] = {0, 1, 0, 1, 0, 1, 0, 1}, val[] = {0, 1, 1, 1, 0, 1, 1, 0};
	for (auto &i : a) {
		cin >> i;
	}
	int64_t dp[n][8][8]{};	//dp[i][j][k] := i+1桁目まで見た時, 最初にjを使い, i+1桁目でkを使った通り数
	for (int j = 0; j < 8; j++) {
		if (a[0] == val[j]) {
			dp[0][j][j] = 1;
		}
	}
	for (int i = 1; i < n - 1; i++) {
		for (int j = 0; j < 8; j++) {
			for (int k = 0; k < 8; k++) {
				for (int l = 0; l < 8; l++) {
					if (val[l] == a[i] && prev[l] == now[k] && now[l] == next[k]) {
						(dp[i][j][l] += dp[i - 1][j][k]) %= mod;
					}
				}
			}
		}
	}
	for (int j = 0; j < 8; j++) {
		for (int k = 0; k < 8; k++) {
			for (int l = 0; l < 8; l++) {
				if (val[l] == a[n - 1] && prev[l] == now[k] && now[l] == next[k] && now[l] == prev[j] && next[l] == now[j]) {
					(dp[n - 1][j][l] += dp[n - 2][j][k]) %= mod;
				}
			}
		}
	}
	int64_t ans = 0;
	for (int j = 0; j < 8; j++) {
		for (int k = 0; k < 8; k++) {
			(ans += dp[n - 1][j][k]) %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}
0