結果

問題 No.406 鴨等間隔の法則
ユーザー aoharu9825
提出日時 2019-07-18 10:41:34
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-07 12:40:14
合計ジャッジ時間 1,792 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

typedef long long int ll;

int MIN(int a, int b){return a>b?b:a;}
int MAX(int a, int b){return a>b?a:b;}
int compare(const void* a, const void* b){
    return *(int*)a - *(int*)b;
}

int main(void){
    int n;
    scanf("%d", &n);

    int x[n];
    int max = -1;
    int min = 100000001;
    for(int i=0; i<n; i++){
        scanf("%d", &x[i]);
        max = MAX(max, x[i]);
        min = MIN(min, x[i]);
    }

    int each = 1;
    if(max == min){
        each = 0;
    }

    qsort(x, n, sizeof(int), compare);

    int res = 1;

    int diff = x[1]-x[0];
    for(int i=1; i<n; i++){
        if(diff != x[i]-x[i-1]){
            res = 0;
            break;
        }
    }

    if(res && each){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    return 0;
}
0