結果

問題 No.1053 ゲーミング棒
ユーザー ks2m
提出日時 2020-05-15 22:02:18
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 548 bytes
コンパイル時間 3,472 ms
コンパイル使用メモリ 74,244 KB
実行使用メモリ 59,396 KB
最終ジャッジ日時 2024-09-19 10:31:26
合計ジャッジ時間 13,348 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

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();

		int[] c = new int[n + 1];
		c[a[0]]++;
		for (int i = 1; i < n - 1; i++) {
			if (a[i] != a[i - 1] && c[a[i]] > 0) {
				System.out.println(-1);
				return;
			}
			c[a[i]]++;
		}
		if (a[0] == a[n - 1]) {
			System.out.println(1);
		} else {
			System.out.println(0);
		}
	}
}
0