結果
問題 |
No.1109 調の判定
|
ユーザー |
|
提出日時 | 2019-11-14 23:06:27 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,437 bytes |
コンパイル時間 | 1,968 ms |
コンパイル使用メモリ | 77,760 KB |
実行使用メモリ | 37,192 KB |
最終ジャッジ日時 | 2024-09-22 04:48:18 |
合計ジャッジ時間 | 5,524 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; public class Main{ public static void main(String args[]) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); if(line.charAt(line.length()-1) == ' ') System.exit(1); int n = Integer.parseInt(line); if(!(1 <= n && n <= 12)) System.exit(1); line = br.readLine(); if(line.charAt(line.length()-1) == ' ') System.exit(1); String[] tmp = line.split(" "); if(tmp.length != n) System.exit(1); int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(tmp[i]); for(int i = 1; i < n; i++){ if(!(arr[i-1] < arr[i])) System.exit(1); } boolean[] x = new boolean[12]; for(int i = 0; i < n; i++){ if(!(0 <= arr[i] && arr[i] < 12)) System.exit(1); x[arr[i]] = true; } int[] add = {0, 2, 4, 5, 7, 9, 11}; int ans = -1; for(int i = 0; i < 12; i++){ int count = 0; for(int j : add){ if(x[(i+j)%12]) count++; } if(count != n) continue; if(ans != -1){ ans = -1; break; } ans = i; } System.out.println(ans); } }