結果

問題 No.1053 ゲーミング棒
ユーザー rlangevin
提出日時 2023-04-28 12:46:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 88,576 KB
最終ジャッジ日時 2024-11-17 13:34:33
合計ジャッジ時間 2,736 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

N = int(input())
A = list(map(int, input().split()))
if N == 2:
    print(0)
    exit()

ans = 0
c = -1
if A[0] == A[-1]:
    c = A[0]
    A = deque(A)
    while A:
        if A[0] == c:
            A.popleft()
        else:
            break
    while A:
        if A[-1] == c:
            A.pop()
        else:
            break
    A = list(A)
    if A == []:
        print(0)
        exit()
    ans = 1

seen = [0] * (N + 1)
pre = -1
for a in A:
    if (a != pre and seen[a]) or a == c:
        print(-1)
        exit()
    pre = a
    seen[a] = 1

print(ans)
0