結果

問題 No.135 とりあえず1次元の問題
ユーザー nukosukenukosuke
提出日時 2016-10-19 16:52:58
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 25,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 00:36:52
合計ジャッジ時間 1,250 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 0 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 20 ms
4,380 KB
evil01.txt AC 13 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int int_sort(const void *a, const void *b) {
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}

int main() {
  int N, *X;
  char *line;

  scanf("%d\n", &N);
  X = (int *)malloc(sizeof(int) * N);

  int length = 6*N + N-1;
  line = (char *)malloc(sizeof(char) * length);
  fgets(line, length, stdin);

  char *delim = " \n";
  char *tok;
  int i = 0;

  tok = strtok(line, delim);
  while(tok != NULL) {
    X[i] = atoi(tok);
    tok = strtok(NULL, delim);
    i++;
  }
  free(line);

  qsort(X, N, sizeof(int), int_sort);

  int answer = 1000001;
  for (i = 0; i < N-1; i++) {
    if (X[i] == X[i+1]) continue;
    int dist = X[i+1] - X[i];
    answer = dist < answer ? dist : answer;
  }

  if (answer == 1000001) answer = 0;
  printf("%d\n", answer);
  free(X);
  return 0;
}
0