結果

問題 No.1053 ゲーミング棒
ユーザー GrayCoder
提出日時 2020-05-16 06:54:56
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 902 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 24,856 KB
最終ジャッジ日時 2024-09-21 18:49:35
合計ジャッジ時間 2,722 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

'''
from math import gcd
from itertools import accumulate, combinations, permutations, product
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
from operator import add, mul, sub, truediv, floordiv, mod

from decimal import *
getcontext().prec = 500

import string
ascii = string.ascii_lowercase
'''
from collections import deque
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = tuple(map(int, input().split()))

    a1 = [A[0]]
    for i in range(1, N):
        if a1[-1] != A[i]:
            a1.append(A[i])

    if len(a1) == 1:
        print(0)
        return

    a2 = deque(a1)
    for _ in [0] * len(a1):
        n = a2.popleft()
        if n != a2[-1]:
            a2.append(n)

    if len(set(a1)) != len(a2):
        print(-1)
    else:
        print(len(a1) - len(a2))


main()
0