結果

問題 No.1053 ゲーミング棒
ユーザー tentententen
提出日時 2021-01-19 14:51:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 3,333 ms
コンパイル使用メモリ 75,936 KB
実行使用メモリ 78,224 KB
最終ジャッジ日時 2023-08-22 12:25:44
合計ジャッジ時間 15,749 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
53,236 KB
testcase_01 AC 124 ms
55,588 KB
testcase_02 AC 126 ms
55,832 KB
testcase_03 AC 126 ms
55,580 KB
testcase_04 AC 127 ms
55,096 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 124 ms
55,808 KB
testcase_12 AC 126 ms
55,524 KB
testcase_13 WA -
testcase_14 AC 127 ms
55,448 KB
testcase_15 AC 127 ms
55,260 KB
testcase_16 AC 126 ms
55,104 KB
testcase_17 AC 124 ms
55,592 KB
testcase_18 AC 125 ms
55,696 KB
testcase_19 WA -
testcase_20 AC 124 ms
55,776 KB
testcase_21 AC 123 ms
55,596 KB
testcase_22 AC 125 ms
55,532 KB
testcase_23 AC 661 ms
76,652 KB
testcase_24 AC 745 ms
78,052 KB
testcase_25 AC 719 ms
78,224 KB
testcase_26 AC 743 ms
77,880 KB
testcase_27 WA -
testcase_28 AC 127 ms
55,668 KB
testcase_29 AC 125 ms
55,592 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 510 ms
62,736 KB
testcase_34 AC 506 ms
62,492 KB
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
		        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);
	}
}
0