結果
| 問題 |
No.1053 ゲーミング棒
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-02-03 22:51:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 2,000 ms |
| コード長 | 615 bytes |
| コンパイル時間 | 236 ms |
| コンパイル使用メモリ | 82,592 KB |
| 実行使用メモリ | 106,064 KB |
| 最終ジャッジ日時 | 2024-06-30 06:03:05 |
| 合計ジャッジ時間 | 3,840 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
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())
tktk_snsn