結果

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

ソースコード

diff #

from collections import *

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

ans = 0
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