結果

問題 No.135 とりあえず1次元の問題
ユーザー nukosukenukosuke
提出日時 2016-10-19 17:05:05
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 841 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 25,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 00:36:57
合計ジャッジ時間 1,387 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 0 ms
4,376 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 9 ms
4,376 KB
testcase_22 AC 19 ms
4,376 KB
evil01.txt AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int int_sort(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

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