結果

問題 No.135 とりあえず1次元の問題
ユーザー Naoki00712Naoki00712
提出日時 2023-06-02 10:05:56
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 687 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 29,000 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-28 02:18:41
合計ジャッジ時間 1,599 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int cmp(const void* n1, const void* n2)
{
	if (*(int*)n1 > *(int*)n2)
	{
		return 1;
	}
	else if (*(int*)n1 < *(int*)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main()
{
	int N;
	scanf("%d", &N);

	int* X;
	X = (int*)malloc(sizeof(int) * N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &X[i]);
	}

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

	int* Y;
	Y = (int*)malloc(sizeof(int) * N);

	int min = X[N - 1];

	if (X[0] == X[N - 1])
	{
		printf("0");
		return 0;
	}

	for (int i = 1; i < N; i++)
	{
		if (X[i - 1] == X[i])
		{
			continue;
		}

		if (X[i - 1] - X[i] < min)
		{
			min = X[i - 1] - X[i];
		}
	}

	printf("%d", min);

	return 0;
}
0