結果

問題 No.1053 ゲーミング棒
ユーザー ks2mks2m
提出日時 2020-05-15 22:16:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 628 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 2,757 ms
コンパイル使用メモリ 79,148 KB
実行使用メモリ 54,496 KB
最終ジャッジ日時 2023-10-19 14:47:17
合計ジャッジ時間 13,262 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
41,080 KB
testcase_01 AC 135 ms
41,080 KB
testcase_02 AC 137 ms
41,240 KB
testcase_03 AC 134 ms
40,948 KB
testcase_04 AC 134 ms
41,116 KB
testcase_05 AC 139 ms
41,088 KB
testcase_06 AC 135 ms
41,116 KB
testcase_07 AC 135 ms
40,996 KB
testcase_08 AC 138 ms
41,144 KB
testcase_09 AC 137 ms
41,152 KB
testcase_10 AC 135 ms
41,180 KB
testcase_11 AC 132 ms
39,864 KB
testcase_12 AC 138 ms
41,052 KB
testcase_13 AC 138 ms
41,008 KB
testcase_14 AC 136 ms
41,088 KB
testcase_15 AC 137 ms
40,988 KB
testcase_16 AC 138 ms
41,092 KB
testcase_17 AC 139 ms
41,044 KB
testcase_18 AC 138 ms
41,116 KB
testcase_19 AC 135 ms
40,904 KB
testcase_20 AC 136 ms
41,088 KB
testcase_21 AC 134 ms
41,104 KB
testcase_22 AC 139 ms
41,096 KB
testcase_23 AC 581 ms
53,152 KB
testcase_24 AC 601 ms
54,464 KB
testcase_25 AC 601 ms
54,496 KB
testcase_26 AC 628 ms
53,200 KB
testcase_27 AC 139 ms
40,852 KB
testcase_28 AC 138 ms
41,120 KB
testcase_29 AC 139 ms
41,156 KB
testcase_30 AC 494 ms
47,872 KB
testcase_31 AC 500 ms
47,856 KB
testcase_32 AC 494 ms
47,824 KB
testcase_33 AC 488 ms
47,856 KB
testcase_34 AC 495 ms
47,880 KB
testcase_35 AC 530 ms
47,948 KB
testcase_36 AC 526 ms
47,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		List<Integer> list = new ArrayList<>();
		list.add(a[0]);
		for (int i = 1; i < n; i++) {
			if (a[i - 1] != a[i]) {
				list.add(a[i]);
			}
		}
		Set<Integer> set = new HashSet<>();
		for (Integer o : list) {
			set.add(o);
		}
		if (set.size() == list.size()) {
			System.out.println(0);
		} else {
			if (set.size() + 1 == list.size() &&
					list.get(0).equals(list.get(list.size() - 1))) {
				System.out.println(1);
			} else {
				System.out.println(-1);
			}
		}
	}
}
0