No.1884 Sequence
タグ : / 解いたユーザー数 167
作問者 :
miscalc
/ テスター :
Problem Statement
$N$ cards are arranged in a row from left to right. Each card either has $1$ positive integer written on it or has nothing written on it. The state of the $i$-th card from the left is represented by a non-negative integer $A_i$ as follows.
- If $A_i > 0$, the integer $A_i$ is written on the $i$-th card from the left.
- If $A_i = 0$, nothing is written on the $i$-th card from the left.
Now, consider performing the following operation on the cards.
- If there are cards with nothing written on them, write $1$ positive integer of your choice on each of them. Then, rearrange all the cards in any order you like (the order may be left as it is).
Let $B_i$ be the integer written on the $i$-th card from the left after the operation. Is it possible to perform the operation so that the sequence $B = (B_1, B_2, \ldots, B_N)$ is an arithmetic progression? That is, is it possible to perform the operation so that $B_2 - B_1 = B_3 - B_2 = \cdots = B_N - B_{N - 1}$ holds?
Input
$N$ $A_1$ $A_2$ $\ldots$ $A_N$
- All inputs are integers.
- $3 \leq N \leq 2 \times 10^5$
- $0 \leq A_i \leq 10^{15}$
Output
Print Yes if it is possible to perform the operation so that $B$ is an arithmetic progression, and No otherwise.
Sample
Sample 1
Input
5 0 7 3 0 9
Output
Yes
By writing $1, 5$ respectively on the $2$ cards with nothing written on them and rearranging the cards, you can make $B = (1, 3, 5, 7, 9)$.
Sample
Sample 2
Input
7 4 0 9 5 11 0 0
Output
No
Sample
Sample 3
Input
4 1 1 0 1
Output
Yes
You can make $B = (1, 1, 1, 1)$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。