結果

問題 No.663 セルオートマトンの逆操作
ユーザー GrenacheGrenache
提出日時 2018-03-12 18:30:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 3,219 ms
コンパイル使用メモリ 74,464 KB
実行使用メモリ 59,132 KB
最終ジャッジ日時 2023-08-08 01:51:17
合計ジャッジ時間 8,676 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,732 KB
testcase_01 AC 122 ms
55,744 KB
testcase_02 AC 122 ms
56,084 KB
testcase_03 AC 121 ms
56,360 KB
testcase_04 AC 121 ms
56,028 KB
testcase_05 AC 124 ms
56,024 KB
testcase_06 AC 122 ms
55,688 KB
testcase_07 AC 122 ms
56,168 KB
testcase_08 AC 123 ms
55,640 KB
testcase_09 AC 123 ms
55,620 KB
testcase_10 AC 124 ms
55,476 KB
testcase_11 AC 124 ms
55,732 KB
testcase_12 AC 123 ms
55,768 KB
testcase_13 AC 124 ms
56,084 KB
testcase_14 AC 122 ms
55,884 KB
testcase_15 AC 124 ms
55,916 KB
testcase_16 AC 130 ms
55,568 KB
testcase_17 AC 125 ms
56,096 KB
testcase_18 AC 123 ms
56,068 KB
testcase_19 AC 124 ms
55,384 KB
testcase_20 AC 132 ms
56,000 KB
testcase_21 AC 139 ms
55,856 KB
testcase_22 AC 177 ms
55,984 KB
testcase_23 AC 175 ms
56,580 KB
testcase_24 AC 192 ms
58,580 KB
testcase_25 AC 195 ms
58,848 KB
testcase_26 AC 197 ms
59,132 KB
testcase_27 AC 121 ms
55,880 KB
testcase_28 AC 121 ms
55,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder663 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		final int MOD = 1_000_000_007;

		int n = sc.nextInt();

		int[] e = new int[n];
		for (int i = 0; i < n; i++) {
			e[i] = sc.nextInt();
		}

		int[] mm = {0, 1, 1, 1, 0, 1, 1, 0};

		long ans = 0;
		for (int s = 0; s < 8; s++) {
			long[][] dp = new long[4][n];

			if (mm[s] != e[0]) {
				continue;
			}
			dp[s & 0x3][0] = 1;

			for (int i = 1; i < n; i++) {
				for (int j = 0; j < 8; j++) {
					if (mm[j] != e[i]) {
						continue;
					}

					dp[j & 0x3][i] += dp[j >> 1][i - 1];
					dp[j & 0x3][i] %= MOD;
				}
			}

			for (int i = 0; i < 4; i++) {
				if (i == s >> 1) {
					ans += dp[i][n - 1];
					ans %= MOD;
				}
			}
		}

		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0