結果

問題 No.1053 ゲーミング棒
ユーザー jp_stejp_ste
提出日時 2020-05-15 22:29:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 77,596 KB
実行使用メモリ 62,316 KB
最終ジャッジ日時 2023-10-19 15:14:37
合計ジャッジ時間 12,571 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,756 KB
testcase_01 AC 131 ms
57,552 KB
testcase_02 AC 128 ms
57,560 KB
testcase_03 AC 125 ms
57,588 KB
testcase_04 AC 124 ms
57,500 KB
testcase_05 AC 123 ms
57,124 KB
testcase_06 AC 123 ms
57,404 KB
testcase_07 AC 125 ms
57,548 KB
testcase_08 AC 133 ms
57,744 KB
testcase_09 AC 125 ms
57,452 KB
testcase_10 AC 124 ms
57,620 KB
testcase_11 AC 126 ms
57,776 KB
testcase_12 AC 126 ms
57,352 KB
testcase_13 AC 127 ms
57,452 KB
testcase_14 AC 127 ms
57,548 KB
testcase_15 AC 126 ms
57,520 KB
testcase_16 AC 126 ms
57,336 KB
testcase_17 AC 130 ms
57,872 KB
testcase_18 AC 123 ms
57,340 KB
testcase_19 AC 113 ms
56,196 KB
testcase_20 AC 125 ms
57,600 KB
testcase_21 AC 129 ms
57,468 KB
testcase_22 AC 131 ms
57,320 KB
testcase_23 AC 532 ms
62,280 KB
testcase_24 AC 536 ms
62,168 KB
testcase_25 AC 507 ms
62,316 KB
testcase_26 AC 547 ms
62,200 KB
testcase_27 AC 125 ms
55,244 KB
testcase_28 AC 123 ms
57,440 KB
testcase_29 AC 126 ms
57,496 KB
testcase_30 AC 438 ms
61,752 KB
testcase_31 AC 489 ms
61,820 KB
testcase_32 AC 422 ms
60,944 KB
testcase_33 AC 451 ms
61,936 KB
testcase_34 AC 458 ms
62,120 KB
testcase_35 AC 537 ms
62,188 KB
testcase_36 AC 492 ms
60,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static Scanner scan = new Scanner(System.in);
	static int N;
	static int[] A;
	static boolean[] F;
	
	public static void main(String[] args) {
		N = scan.nextInt();
		A = new int[N];
		F = new boolean[N];
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		}
		
		if(A[0] == A[N-1]) {
			int now = A[0];
			for(int i=1; i<N; i++) {
				if(now != A[i]) {
					if(check(i)) {
						System.out.println(1);
					} else {
						System.out.println(-1);
					}
					System.exit(0);
				}
			}
			System.out.println(0);
		} else {
			if(check(0)) {
				System.out.println(0);
			} else {
				System.out.println(-1);
			}
		}
	}
	
	static boolean check(int first) {
		int count = 0;
		int last = -1;
		for(int i=first; i<N; i++) {
			if(last == A[i]) {
				count++;
			} else {
				count = 0;
			}
			if(count == 0 && F[A[i]-1]) {
				return false;
			}
			F[A[i]-1] = true;
			last = A[i];
		}
		return true;
	}
}
0