結果

問題 No.1717 Levi-Civita Triangle
コンテスト
ユーザー 👑 SPD_9X2
提出日時 2025-10-26 01:52:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,486 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 82,980 KB
実行使用メモリ 132,884 KB
最終ジャッジ日時 2025-10-26 01:52:47
合計ジャッジ時間 6,203 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1717

すぐに0だけになる?


0 2 1 2 0 2 1 2 0 2 1 2 0

0 1 0 2

"""

def move(A):
    B = []

    for i in range(len(A)-2):

        tup = (A[i],A[i+1],A[i+2])

        if tup in ( (0,1,2),(1,2,0),(2,0,1) ):
            B.append(1)
        elif tup in ( (2,1,0),(1,0,2),(0,2,1) ):
            B.append(2)
        else:
            B.append(0)

    return B

def check(A):

    if len(A) < 20:
        while len(A) != 1:
            A = move(A)
        return A[0]

    if sum(A) == 0:
        return 0

    for i in range(len(A)-1):
        if A[i] == A[i+1] == 0:
            return 0

    flag = True
    for i in range(len(A)-2):
        if A[i] == 0 and A[i+2] != 0:
            flag = False
        if A[i] == 1 and A[i+2] != 2:
            flag = False
        if A[i] == 2 and A[i+2] != 1:
            flag = False
    for i in range(len(A)-1):
        if A[i] != 0 and A[i+1] != 0:
            flag = False
        if A[i] == 0 and A[i+1] == 0:
            flag = False

    if flag:
        a0 = A
        a1 = move(A)
        a2 = move(a1)
        a3 = move(a2)

        alis = [ a0[len(a0)//2] , a1[len(a1)//2] , a2[len(a2)//2] , a3[len(a3)//2] ]
        L = len(A)
        idx = 0
        while L != 1:
            idx += 1
            L -= 2
        return alis[idx%4]

    return check(move(A))
        

N = int(input())
A = list(map(int,input().split()))

if len(A) == 1:
    print (A[0])
else:
    print (check(move(A)))
0