結果

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

ソースコード

diff #
raw source code

#include <stdio.h>

void Quicksort(int data[], int left, int right){
    int l = left, r = right;
    int pivot = data[(left + right) / 2];
    int temp;

    while(1){
        while (data[l] < pivot) l++;
        while (pivot < data[r]) r--;
        if(r < l) break;

        temp = data[l];
        data[l] = data[r];
        data[r] = temp;

        l++, r--;
    }
    if(left < r)  Quicksort(data, left, r);
    if(l < right) Quicksort(data, l, right);
}

int main(void){
    int i, N, same = 0, ans = 1000000;
    scanf("%d", &N);
    if(N-1){
        int x[N+1];
        for(i=1;i<=N;i++){
            scanf("%d", &x[i]);
        }
        Quicksort(x, 1, N);
        for(i=1;i<N;i++){
            if(x[i]==x[i+1]){
                same++;
            }else if(x[i+1]-x[i]<ans){
                ans = x[i+1]-x[i];
            }
        }
        if(same==N-1){
            printf("0\n");
        }else{
            printf("%d\n", ans);
        }
    }else{
        scanf("%d", &N);
        printf("0\n");
    }
    return 0;
}
0