結果

問題 No.406 鴨等間隔の法則
ユーザー matsuyoshi30
提出日時 2016-08-14 11:15:45
言語 Java
(openjdk 23)
結果
AC  
実行時間 700 ms / 2,000 ms
コード長 759 bytes
コンパイル時間 3,244 ms
コンパイル使用メモリ 76,192 KB
実行使用メモリ 60,724 KB
最終ジャッジ日時 2024-07-07 11:37:52
合計ジャッジ時間 17,618 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] x = new long[n];
        for(int i=0; i<n; i++) {
            x[i] = in.nextLong();
        }
        Arrays.sort(x);
        final long diff = x[1] - x[0];
        if(diff == 0) {
            System.out.println("NO");
        } else {
            for(int i=2; i<n; i++) {
                if(diff != x[i] - x[i-1]) {
                    System.out.println("NO");
                    return;
                }
            }
            System.out.println("YES");
        }

        in.close();
    }
}
0