結果
問題 | No.1053 ゲーミング棒 |
ユーザー |
![]() |
提出日時 | 2025-03-26 15:57:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 141 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 110,360 KB |
最終ジャッジ日時 | 2025-03-26 15:58:10 |
合計ジャッジ時間 | 3,804 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
n = int(input())a = list(map(int, input().split()))from collections import defaultdictblock_count = defaultdict(int)prev = Nonefor num in a:if num != prev:block_count[num] += 1prev = numfirst = {}last = {}for i in range(n):num = a[i]if num not in first:first[num] = ilast[num] = ipossible = Truefor c in block_count:bc = block_count[c]if bc == 1:continueelif bc == 2:if a[0] == c and a[-1] == c:continueelse:possible = Falsebreakelse:possible = Falsebreakif not possible:print(-1)else:valid = Truefor c in first:left = first[c]right = last[c]for i in range(left, right + 1):if a[i] != c:valid = Falsebreakif not valid:breakif valid:print(0)else:print(1)