問題一覧 > 通常問題

No.406 The Law of Equally Spaced Ducks

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 256 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 604
作問者 : はむ吉🐹 / テスター : btk
お気に入りにしたユーザー ProblemId : 1221 / 自分の提出
問題文最終更新日: 2026-06-25 05:24:36
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 145 (順位表) の他の問題:

Problem Statement

Taro found $N (\ge 3)$ ducks resting on a riverbank near his home. This riverbank is straight. So, taking a certain point upstream as the origin $x = 0$, he represents the position where each duck is resting as a point on the part of the $x$-axis satisfying $x\ge 0$. Then, these $N$ ducks are said to satisfy the Law of Equally Spaced Ducks if and only if the following two conditions hold simultaneously.

  1. The coordinates of any two ducks are distinct.
  2. The differences between the coordinates of adjacent pairs of ducks are all equal.
Taro recorded the number of ducks $N$ and the coordinates $x_0, x_1, \cdots, x_{N-1}$ where the ducks are resting. Given these, determine whether the $N$ ducks satisfy the Law of Equally Spaced Ducks.

Input

$N$
$x_0$ $x_1$ $\cdots$ $x_{N - 1}$

The first line contains the number of ducks $N\:(3 \le N \le 10 ^ 5$) that Taro found, as a positive integer.
The second line contains the coordinates $x_i\:(0 \le x_i \le 10 ^ 8)$ where duck $i (0 \le i \le N - 1)$ is resting, as non-negative integers separated by spaces. Note that it is not necessarily the case that "if $j \lt k$ then $x_j \lt x_k$".

Output

Print the string YES if the $N$ ducks satisfy the Law of Equally Spaced Ducks, and the string NO otherwise. Print a newline at the end.

Sample

Sample 1
Input
3
12 0 6
Output
YES

Whichever two ducks are chosen, their coordinates are different. Also, the differences between the coordinates of adjacent pairs of ducks are 6 - 0 and 12 - 6, both of which are 6. Therefore, both conditions hold, so the Law of Equally Spaced Ducks is satisfied.

Sample 2
Input
5
63 17 99 34 51
Output
NO

Taking the differences between the coordinates of adjacent pairs of ducks gives 34 - 17 = 17, 51 - 34 = 17, 63 - 51 = 12, 99 - 63 = 36, which violates condition 2. Therefore, these ducks do not satisfy the Law of Equally Spaced Ducks.

Sample 3
Input
10
1299709 1299709 1299709 1299709 1299709 1299709 1299709 1299709 1299709 1299709
Output
NO

This violates condition 1. At this point, it is clear that the Law of Equally Spaced Ducks is not satisfied. Note that coordinates can be large values.

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