問題一覧 > 通常問題

No.135 A One-Dimensional Problem for Now

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 663
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 135 / 自分の提出
問題文最終更新日: 2026-06-28 19:25:56
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 79 (順位表) の他の問題:

Problem Statement

There are $N$ points at integer coordinates on a number line.

Choose $2$ points among them that are not at the same coordinate, and find the distance between those $2$ points.
Letting $X_i$ be the coordinate of the $i$-th point and $X_j$ the coordinate of the $j$-th point, the distance is defined as
the absolute value $|X_i-X_j|$.

Here, suppose you choose the 2 points with the minimum distance. Find the minimum distance between the chosen $2$ points.
If it is impossible to choose $2$ points satisfying the condition, output $0$.

Input

$N$
$X_1\ X_2\ \dots\ X_N$

All inputs are given as integers.
・$1\le N \le 100000=10^5$
・$0\le X_i \le 1000000=10^6, 1\le i \le N$

Output

Output the minimum distance between $2$ points satisfying the condition.
If $2$ points cannot be chosen, output $0$.

Print a newline at the end.

Sample

Sample 1
Input
3
0 51 100
Output
49

Choosing the points at coordinates $51$ and $100$ gives the minimum distance $49$.

Sample 2
Input
4
0 1 1 0
Output
1

Points at the same coordinate may be given.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。