結果

問題 No.663 セルオートマトンの逆操作
ユーザー GrenacheGrenache
提出日時 2018-03-12 18:30:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 4,210 ms
コンパイル使用メモリ 78,296 KB
実行使用メモリ 57,076 KB
最終ジャッジ日時 2024-04-25 19:50:09
合計ジャッジ時間 7,911 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
54,004 KB
testcase_01 AC 124 ms
54,032 KB
testcase_02 AC 120 ms
54,052 KB
testcase_03 AC 122 ms
54,156 KB
testcase_04 AC 107 ms
53,176 KB
testcase_05 AC 120 ms
54,332 KB
testcase_06 AC 123 ms
54,160 KB
testcase_07 AC 108 ms
53,100 KB
testcase_08 AC 118 ms
54,416 KB
testcase_09 AC 116 ms
54,012 KB
testcase_10 AC 116 ms
53,980 KB
testcase_11 AC 106 ms
53,152 KB
testcase_12 AC 114 ms
54,192 KB
testcase_13 AC 122 ms
54,000 KB
testcase_14 AC 120 ms
53,988 KB
testcase_15 AC 116 ms
54,140 KB
testcase_16 AC 112 ms
52,788 KB
testcase_17 AC 123 ms
54,316 KB
testcase_18 AC 122 ms
54,156 KB
testcase_19 AC 108 ms
52,964 KB
testcase_20 AC 130 ms
54,324 KB
testcase_21 AC 149 ms
54,164 KB
testcase_22 AC 154 ms
54,480 KB
testcase_23 AC 177 ms
54,504 KB
testcase_24 AC 190 ms
56,908 KB
testcase_25 AC 176 ms
56,736 KB
testcase_26 AC 195 ms
57,076 KB
testcase_27 AC 110 ms
52,944 KB
testcase_28 AC 120 ms
54,144 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