結果

問題 No.1053 ゲーミング棒
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-03 22:51:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 615 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 110,632 KB
最終ジャッジ日時 2023-09-12 18:21:47
合計ジャッジ時間 6,090 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,416 KB
testcase_01 AC 69 ms
71,324 KB
testcase_02 AC 71 ms
71,228 KB
testcase_03 AC 71 ms
71,328 KB
testcase_04 AC 71 ms
71,100 KB
testcase_05 AC 70 ms
71,492 KB
testcase_06 AC 69 ms
71,320 KB
testcase_07 AC 71 ms
71,516 KB
testcase_08 AC 71 ms
71,324 KB
testcase_09 AC 71 ms
71,436 KB
testcase_10 AC 71 ms
71,328 KB
testcase_11 AC 69 ms
71,220 KB
testcase_12 AC 72 ms
71,324 KB
testcase_13 AC 70 ms
71,272 KB
testcase_14 AC 71 ms
71,392 KB
testcase_15 AC 70 ms
71,264 KB
testcase_16 AC 70 ms
71,536 KB
testcase_17 AC 69 ms
71,308 KB
testcase_18 AC 71 ms
71,552 KB
testcase_19 AC 71 ms
71,232 KB
testcase_20 AC 71 ms
71,456 KB
testcase_21 AC 69 ms
71,088 KB
testcase_22 AC 69 ms
71,308 KB
testcase_23 AC 123 ms
110,572 KB
testcase_24 AC 117 ms
110,456 KB
testcase_25 AC 113 ms
110,632 KB
testcase_26 AC 113 ms
110,616 KB
testcase_27 AC 70 ms
71,268 KB
testcase_28 AC 71 ms
71,240 KB
testcase_29 AC 70 ms
71,120 KB
testcase_30 AC 89 ms
88,508 KB
testcase_31 AC 88 ms
88,820 KB
testcase_32 AC 89 ms
88,884 KB
testcase_33 AC 88 ms
88,664 KB
testcase_34 AC 89 ms
88,640 KB
testcase_35 AC 90 ms
88,888 KB
testcase_36 AC 90 ms
89,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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