結果
| 問題 | No.663 セルオートマトンの逆操作 | 
| コンテスト | |
| ユーザー |  maspy | 
| 提出日時 | 2020-02-29 00:41:27 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 32 ms / 2,000 ms | 
| コード長 | 773 bytes | 
| コンパイル時間 | 158 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 10,752 KB | 
| 最終ジャッジ日時 | 2024-10-13 19:37:26 | 
| 合計ジャッジ時間 | 1,983 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 29 | 
ソースコード
#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7
# %%
N, *B = map(int, read().split())
# %%
def solve(B, end, start):
    dp = [0, 0, 0, 0]
    dp[2 * end + start] = 1
    for x in B:
        newdp = [0, 0, 0, 0]
        if x == 0:
            newdp[0] += dp[0]
            newdp[0] += dp[2]
            newdp[3] += dp[3]
        elif x == 1:
            newdp[1] += dp[0]
            newdp[2] += dp[1]
            newdp[3] += dp[1]
            newdp[1] += dp[2]
            newdp[2] += dp[3]
        dp = [x % MOD for x in newdp]
    return dp[2 * end + start]
# %%
answer = sum(solve(B, i, j) for i in [0, 1] for j in [0, 1])
answer %= MOD
print(answer)
            
            
            
        