問題一覧 > 通常問題

No.2836 Comment Out

レベル : / AI推定難易度 : 1475 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 152
作問者 : milkcoffee / テスター : nonon ygussany
お気に入りにしたユーザー ProblemId : 11212 / 自分の提出
問題文最終更新日: 2024-08-03 20:23:40
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 440 (順位表) の他の問題:

Problem Statement

There is a sequence $X$ of non-negative integers of length $N$. Initially, all elements of $X$ are $0$.

You can perform the following operation on $X$.

  • Choose integers $l,r \ (1 \leq l \leq r \leq N)$. If $X_l,X_{l+1},\dots,X_r$ contains a $0$, increase each of $X_l,X_{l+1},\dots,X_r$ by $1$. Otherwise, decrease each of $X_l,X_{l+1},\dots,X_r$ by $1$.

You are given a sequence $A$ of non-negative integers of length $N$. Determine whether it is possible to make $X$ equal to $A$ by performing the operation $0$ or more times on $X$.

Input

$N$
$A_1$ $A_2$ $\dots$ $A_N$

  • $1 \leq N \leq 2 \times 10^5$
  • $0 \leq A_i \leq 10^9 \ (1 \leq i \leq N)$
  • All inputs are integers.

Output

Print Yes if it is possible to make $X$ equal to $A$, and No otherwise.

Sample

Sample 1
Input
4
0 1 2 1
Output
Yes

Initially, $X=(0,0,0,0)$. You can make $X=(0,1,2,1)$ by the following steps.

  • Perform the operation with $(l,r) = (1,3)$, which makes $X=(1,1,1,0)$.
  • Perform the operation with $(l,r) = (2,4)$, which makes $X=(1,2,2,1)$.
  • Perform the operation with $(l,r) = (1,2)$, which makes $X=(0,1,2,1)$.
Sample 2
Input
3
1000000000 1000000000 1000000000
Output
No

It is impossible to make $X = (10^9,10^9,10^9)$.

Sample 3
Input
1
1
Output
Yes

You can perform the operation with $(l,r)=(1,1)$.

Sample 4
Input
23
14 17 92 97 93 75 3 76 56 33 41 37 77 67 19 7 67 58 78 99 88 5 91
Output
No

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