結果

問題 No.1053 ゲーミング棒
ユーザー hedwig100
提出日時 2020-05-15 21:50:12
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 36,544 KB
最終ジャッジ日時 2024-09-19 09:28:38
合計ジャッジ時間 3,046 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():  
    N = int(input())
    A = list(map(int,input().split()))
    X = []
    for i in range(N - 1):
        if A[i] != A[i + 1]:
            X.append(A[i])
    X.append(A[-1])
    if len(set(X)) == 1:
        print(0)
        return
    dic = {}
    for i in range(len(X)):
        if X[i] in dic:
            dic[X[i]].append(i)
        else:
            dic[X[i]] = [i]
    ans = 0
    M = len(X)
    for v in dic.values():
        if len(v) > 2:
            print(-1)
            return
        if len(v) == 2:
            if sum(v) == M - 1:
                ans += 1
            else:
                print(-1)
                return

    print(ans)   
if __name__ == '__main__':
    main()
0