201381: [AtCoder]ARC138 B - 01 Generation

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

Snuke is about to make an integer sequence of length $N$ consisting of $0$ and $1$. He starts with an empty sequence $x$ and does the following two kinds of operations $N$ times in total, in any order he likes.

  • Operation A: Flip every element of $x$, that is, convert each $0$ to $1$ and vice versa. Then, add $0$ to the beginning of $x$.
  • Operation B: Add $0$ to the end of $x$.

You are given an integer sequence of length $N$ consisting of $0$ and $1$: $A=(A_1,A_2,\cdots,A_N)$. Determine whether it is possible to make $x$ equal to $A$.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $0 \leq A_i \leq 1$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\cdots$ $A_N$

Output

If it is possible to make $x$ equal to $A$, print Yes; otherwise, print No.


Sample Input 1

4
0 1 1 0

Sample Output 1

Yes

Snuke can do the following.

  • Start with $x=()$
  • Do operation A, making $x=(0)$.
  • Do operation B, making $x=(0,0)$.
  • Do operation A, making $x=(0,1,1)$.
  • Do operation B, making $x=(0,1,1,0)$.

Sample Input 2

4
1 0 0 0

Sample Output 2

No

Sample Input 3

4
0 0 0 1

Sample Output 3

No

Input

题意翻译

给定一个长度为 $n$ 的 01 串,并给出 A B 两种操作,要求判断是否可以由一个空串通过这两种操作构造出该 01 串。 两种操作分别为: - A 操作:将串中的每一位翻转,即 $0$ 变成 $1$,$1$ 变成 $0$,最后再在串的最前面追加一个 $0$。 - B 操作:在串的最后面追加一个 $0$。 如果可以构造出来,输出 `Yes`,否则输出 `No`。 翻译:@[KaiserWilheim](https://www.luogu.com.cn/user/196903)

加入题单

上一题 下一题 算法标签: