結果

問題 No.406 鴨等間隔の法則
ユーザー tenten
提出日時 2020-11-11 14:51:41
言語 Java
(openjdk 23)
結果
AC  
実行時間 726 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 74,808 KB
実行使用メモリ 49,664 KB
最終ジャッジ日時 2024-07-22 18:30:13
合計ジャッジ時間 19,569 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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