結果

問題 No.135 とりあえず1次元の問題
コンテスト
ユーザー ゆるく
提出日時 2015-01-28 02:03:01
言語 C90(gcc12)
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 1,837 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 451 ms
コンパイル使用メモリ 32,696 KB
最終ジャッジ日時 2026-02-23 18:06:36
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:35:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |   scanf("%d", &n);
      |   ^~~~~~~~~~~~~~~
main.c:37:13: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   rep(i, n) scanf("%d", &b[i]);
      |             ^~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

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

typedef long long ll;
#define MAX_N 112233
#define REP(i, x, n) for(i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 0x7FFFFFFF
#define ALLOCA(type, n) ((type*)alloca(sizeof(type) * (n)))
#define MALLOC(type, n) ((type*)malloc(sizeof(type) * (n)))
#define CALLOC(type, n) ((type*)calloc((n), sizeof(type)))
#define REALLOC(type, n, p) ((type*)realloc((p), sizeof(type) * (n)))

typedef struct heap_queue{long *data;long size;}hq;
void heappush(hq *q,int data){long i = q->size;q->size++;while(i > 0){long p = (i - 1) / 2;if (q->data[p]<=data){break;}q->data[i] = q->data[p];i=p;}q->data[i] = data;}
long heappop(hq *q){long ret = q->data[0];q->size--;long data = q->data[q->size];long i = 0;while(i * 2 + 1 < q->size) {long a = i * 2 + 1, b = i * 2 + 2;if (b < q->size && q->data[b] < q->data[a]) {a=b;}if (q->data[a] >= data) {break;}q->data[i] = q->data[a];i=a;}q->data[i]=data;return ret;}

#define SORT(h, n) qsort(h, n, sizeof(h[0]), ASC)
#define RSORT(h, n) qsort(h, n, sizeof(h[0]), DESC)
int ASC(const void *c1,const void *c2){int tmp1=*(int *)c1;int tmp2=*(int *)c2;if(tmp1<tmp2){return -1;}if(tmp1==tmp2){return 0;}if(tmp1>tmp2){return 1;}}
int DESC(const void *c1,const void *c2){int tmp1 = *(int *)c1;int tmp2=*(int *)c2;if(tmp1>tmp2){return -1;}if(tmp1==tmp2){return  0;}if(tmp1<tmp2){return 1;}}

int Gcd(int m, int n){return (n <= 0) ? m:Gcd(n, m % n);}
int Bcd(int m, int n){return m * n / Gcd(m, n);}

int main(void)
{
  int i,j,k;
  int *b;
  int n;
  int m = INF;
  int tmp;
  scanf("%d", &n);
  b = MALLOC(int, n + 1);
  rep(i, n) scanf("%d", &b[i]);
  SORT(b, n);
  rep(j, n - 1) {
    tmp = abs(b[j] - b[j + 1]);
    if (tmp < m && tmp != 0) {
      m = tmp;
    }
  }
  printf("%d\n", m != INF ? m:0);
  free(b);
  return 0;
}
0