結果

問題 No.663 セルオートマトンの逆操作
コンテスト
ユーザー rlangevin
提出日時 2024-01-17 12:47:34
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 832 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 187 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 78,848 KB
最終ジャッジ日時 2026-04-14 20:06:08
合計ジャッジ時間 2,555 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
e = []
for i in range(N):
    e.append(int(input()))
    
dp = [[[0] * 4 for _ in range(N)] for _ in range(4)]
for i in range(4):
    dp[i][1][i] = 1
    
S = [[0, 4, 7], [1, 2, 3, 5, 6]]
mod = 10 ** 9 + 7
for a in range(4):
    for n in range(2, N):
        for x in range(4):
            for i in range(2):
                now = x * 2 + i
                if now not in S[e[n - 1]]:
                    continue
                nx = now % 4
                dp[a][n][nx] += dp[a][n-1][x]
                dp[a][n][nx] %= mod
                
ans = 0
for a in range(4):
    for b in range(4):
        nx = b % 2 * 4 + a
        if nx not in S[e[0]]:
            continue
        nx = b * 2 + a // 2
        if nx not in S[e[-1]]:
            continue
        ans += dp[a][-1][b]
        ans %= mod
        
print(ans)
0