結果

問題 No.663 セルオートマトンの逆操作
ユーザー rlangevinrlangevin
提出日時 2024-01-17 12:47:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 832 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 77,228 KB
最終ジャッジ日時 2024-01-17 12:47:37
合計ジャッジ時間 3,276 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 34 ms
53,460 KB
testcase_05 AC 35 ms
53,460 KB
testcase_06 AC 34 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 35 ms
53,460 KB
testcase_09 AC 35 ms
53,460 KB
testcase_10 AC 35 ms
53,460 KB
testcase_11 AC 39 ms
53,460 KB
testcase_12 AC 35 ms
53,460 KB
testcase_13 AC 35 ms
53,460 KB
testcase_14 AC 35 ms
53,460 KB
testcase_15 AC 36 ms
53,460 KB
testcase_16 AC 42 ms
59,832 KB
testcase_17 AC 35 ms
53,460 KB
testcase_18 AC 36 ms
53,460 KB
testcase_19 AC 35 ms
53,460 KB
testcase_20 AC 46 ms
62,224 KB
testcase_21 AC 57 ms
66,396 KB
testcase_22 AC 64 ms
70,540 KB
testcase_23 AC 74 ms
72,596 KB
testcase_24 AC 92 ms
76,848 KB
testcase_25 AC 86 ms
76,976 KB
testcase_26 AC 85 ms
77,228 KB
testcase_27 AC 37 ms
53,460 KB
testcase_28 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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