結果
問題 | No.1053 ゲーミング棒 |
ユーザー |
![]() |
提出日時 | 2020-05-15 22:29:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 566 ms / 2,000 ms |
コード長 | 957 bytes |
コンパイル時間 | 1,871 ms |
コンパイル使用メモリ | 76,724 KB |
実行使用メモリ | 48,908 KB |
最終ジャッジ日時 | 2024-09-19 11:22:04 |
合計ジャッジ時間 | 11,717 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
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; } }