結果
| 問題 |
No.135 とりあえず1次元の問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-19 17:05:05 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 5,000 ms |
| コード長 | 841 bytes |
| コンパイル時間 | 410 ms |
| コンパイル使用メモリ | 23,424 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-11 07:01:52 |
| 合計ジャッジ時間 | 1,200 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:14:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d\n", &N);
| ^~~~~~~~~~~~~~~~~
main.c:19:3: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | fgets(line, length, stdin);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}