結果

問題 No.1109 調の判定
コンテスト
ユーザー face4
提出日時 2019-11-14 23:06:27
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 30 ms / 2,000 ms
+ 559µs
コード長 1,437 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,311 ms
コンパイル使用メモリ 83,656 KB
実行使用メモリ 43,628 KB
最終ジャッジ日時 2026-09-02 04:35:17
合計ジャッジ時間 4,756 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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);
    }
}
0