結果

問題 No.663 セルオートマトンの逆操作
ユーザー nebukuro09nebukuro09
提出日時 2018-03-29 11:46:14
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,171 bytes
コンパイル時間 943 ms
コンパイル使用メモリ 102,116 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-03 19:03:26
合計ジャッジ時間 2,416 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp.to!int).array;
    auto pattern = [0, 1, 1, 1, 0, 1, 1, 0];
    long ans = 0;
    
    foreach (init; 0..2^^3) {
        if (pattern[init] != A[0]) continue;
        auto dp = new long[][](N, 2^^3);
        dp[0][init] = 1;
        
        foreach (i; 1..N-1) {
            foreach (cur; 0..2^^3) {
                foreach (tar; 0..2^^3) {
                    if ((cur & 0b011) != (tar >> 1)) continue;
                    if (pattern[tar] != A[i]) continue;
                    dp[i][tar] += dp[i-1][cur];
                    dp[i][tar] %= MOD;
                }
            }
        }

        foreach (last; 0..2^^3) {
            if ((last & 0b001) != (init >> 2)) continue;
            if (pattern[((last & 0b011) << 1) | ((init & 0b010) >> 1)] != A[N-1]) continue;
            ans += dp[N-2][last];
            ans %= MOD;
        }
    }

    ans.writeln;
}
0