結果

問題 No.1053 ゲーミング棒
コンテスト
ユーザー tktk_snsn
提出日時 2021-02-03 22:51:47
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 93 ms / 2,000 ms
+ 516µs
コード長 615 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 566 ms
コンパイル使用メモリ 95,580 KB
実行使用メモリ 117,888 KB
最終ジャッジ日時 2026-08-02 05:58:29
合計ジャッジ時間 4,846 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def RunLengthEncoding(S):
    res = []
    N = len(S)
    i = 0
    while i < N:
        cnt = 1
        while i < N - 1 and S[i] == S[i + 1]:
            cnt += 1
            i += 1
        res.append((S[i], cnt))
        i += 1
    return res


def main():
    N = int(input())
    A = list(map(int, input().split()))
    rle = RunLengthEncoding(A)

    if len(rle) == 1:
        return 0

    ans = 0
    if rle[0][0] == rle[-1][0]:
        rle.pop()
        ans = 1

    memo = set()
    for color, _ in rle:
        if color in memo:
            return -1
        memo.add(color)
    return ans


print(main())
0