結果

問題 No.663 セルオートマトンの逆操作
ユーザー fumofumofunifumofumofuni
提出日時 2023-06-21 01:40:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 77,752 KB
最終ジャッジ日時 2023-09-10 21:18:36
合計ジャッジ時間 4,181 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,548 KB
testcase_01 AC 73 ms
71,128 KB
testcase_02 AC 73 ms
71,348 KB
testcase_03 AC 72 ms
71,448 KB
testcase_04 AC 73 ms
71,412 KB
testcase_05 AC 71 ms
71,540 KB
testcase_06 AC 71 ms
71,468 KB
testcase_07 AC 71 ms
71,348 KB
testcase_08 AC 75 ms
71,152 KB
testcase_09 AC 74 ms
71,548 KB
testcase_10 AC 74 ms
71,320 KB
testcase_11 AC 72 ms
71,348 KB
testcase_12 AC 74 ms
71,448 KB
testcase_13 AC 73 ms
71,132 KB
testcase_14 AC 73 ms
71,512 KB
testcase_15 AC 72 ms
71,260 KB
testcase_16 AC 74 ms
71,296 KB
testcase_17 AC 73 ms
71,392 KB
testcase_18 AC 72 ms
71,536 KB
testcase_19 AC 72 ms
71,268 KB
testcase_20 AC 79 ms
76,208 KB
testcase_21 AC 84 ms
76,528 KB
testcase_22 AC 97 ms
76,436 KB
testcase_23 AC 102 ms
76,584 KB
testcase_24 AC 122 ms
77,588 KB
testcase_25 AC 112 ms
77,752 KB
testcase_26 AC 112 ms
77,664 KB
testcase_27 AC 75 ms
71,300 KB
testcase_28 AC 73 ms
71,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=[0]*N
for i in range(N):
    A[i]=int(input())
ans = 0
mod =1000000007
for i in range(2):
    for j in range(2):
        dp=[0]*4
        dp[i*2+j]=1
        for k in range(1,N-1):
            ndp=[0]*4
            if A[k]==0:
                ndp[3]+=dp[3]
                ndp[0]+=dp[0]
                ndp[0]+=dp[2]
            else :
                ndp[1]+=dp[0]
                ndp[2]+=dp[1]
                ndp[3]+=dp[1]
                ndp[1]+=dp[2]
                ndp[2]+=dp[3]
            for l in range(4):
                ndp[l]%=mod
                dp[l]=ndp[l]
        for k in range(4):
            p=1
            if i==0 and j==0:
                p=0
            if k%2==1 and i==1 and j==1:
                p=0
            q=1
            if k%2==0 and i==0:
                q=0
            if k//2==1 and k%2==1 and i==1:
                q=0
            if A[0]==p and A[N-1]==q:
                ans += dp[k]
             


print(ans%mod)
0