結果
問題 | No.1053 ゲーミング棒 |
ユーザー |
|
提出日時 | 2021-02-26 01:40:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 534 bytes |
コンパイル時間 | 399 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 108,672 KB |
最終ジャッジ日時 | 2024-10-01 17:20:22 |
合計ジャッジ時間 | 3,135 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
def deg(A): """ 連続して続く文字を圧縮する(※Counterではない) [1,1,1,2,2,2,3] -> [(1,3),(2,3),(3,1)] """ res=[] a0, cnt=A[0], 1 for a in A[1:]: if a!=a0: res.append(a0); cnt=1 else: cnt+=1 a0=a res.append(a0) return res from collections import Counter N=int(input()) A=list(map(int, input().split())) B=deg(A) c=Counter(B) for a in B[1:-1]: if c[a]>=2: print(-1) exit() if A[0]==A[-1] and len(c)>=2: print(1) else: print(0)