結果
問題 |
No.1053 ゲーミング棒
|
ユーザー |
![]() |
提出日時 | 2021-01-19 14:53:02 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 779 ms / 2,000 ms |
コード長 | 919 bytes |
コンパイル時間 | 3,395 ms |
コンパイル使用メモリ | 79,696 KB |
実行使用メモリ | 72,688 KB |
最終ジャッジ日時 | 2024-12-16 09:27:09 |
合計ジャッジ時間 | 15,610 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayDeque<Integer> deq = new ArrayDeque<>(); HashMap<Integer, ArrayList<Integer>> positions = new HashMap<>(); int idx = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (deq.size() == 0 || deq.peekLast() != x) { if (!positions.containsKey(x)) { positions.put(x, new ArrayList<>()); } positions.get(x).add(idx); deq.add(x); idx++; } } int count = 0; for (ArrayList<Integer> list : positions.values()) { if (list.size() <= 1) { continue; } if (list.size() == 2 && list.get(0) == 0 && list.get(1) == idx - 1) { count++; continue; } System.out.println(-1); return; } System.out.println(count); } }