結果

問題 No.406 鴨等間隔の法則
ユーザー akakimidoriakakimidori
提出日時 2016-12-10 18:03:57
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,030 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 25,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 18:20:34
合計ジャッジ時間 2,085 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 14 ms
4,376 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 20 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 17 ms
4,380 KB
testcase_25 AC 15 ms
4,376 KB
testcase_26 AC 24 ms
4,376 KB
testcase_27 AC 14 ms
4,376 KB
testcase_28 AC 14 ms
4,376 KB
testcase_29 AC 24 ms
4,380 KB
testcase_30 AC 24 ms
4,376 KB
testcase_31 AC 14 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void sort_q(int *a,int n){
  if(n<=8) return;

  int p=rand()%n;
  int pivot=a[p];
  a[p]=a[0];

  int l=1;
  int r=n-1;
  while(l<=r){
    if(a[l]==pivot){
      printf("NO\n");
      exit(0);
    } else if(a[l]<pivot){
      a[l-1]=a[l];
      l++;
    } else {
      int swap=a[r];
      a[r]=a[l];
      a[l]=swap;
      r--;
    }
  }
  a[r]=pivot;

  sort_q(a,r);
  sort_q(a+r+1,n-r-1);
}

void sort406(int *a,int n){
  sort_q(a,n);

  int i;
  for(i=1;i<n;i++){
    int p=a[i];
    int j=i-1;
    while(j>=0 && a[j]>p){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=p;
  }
  return;
}

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

  int *x;
  x=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++){
    scanf("%d",x+i);
  }
  srand((unsigned)time(NULL));
  sort406(x,n);
  int d=x[1]-x[0];

  i=2;
  while(i<n && x[i]-x[i-1]==d){
    i++;
  }
  if(i==n){
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return;
}

int main(void){
  run();
  return 0;
}
0