博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #527-D1. Great Vova Wall (Version 1)(思维+栈)
阅读量:4599 次
发布时间:2019-06-09

本文共 2646 字,大约阅读时间需要 8 分钟。

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.

The current state of the wall can be respresented by a sequence aa of nn integers, with aiai being the height of the ii-th part of the wall.

Vova can only use 2×12×1 bricks to put in the wall (he has infinite supply of them, however).

Vova can put bricks horizontally on the neighboring parts of the wall of equal height. It means that if for some ii the current height of part iiis the same as for part i+1i+1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 11 of the wall or to the right of part nn of it).

The next paragraph is specific to the version 1 of the problem.

Vova can also put bricks vertically. That means increasing height of any part of the wall by 2.

Vova is a perfectionist, so he considers the wall completed when:

  • all parts of the wall has the same height;
  • the wall has no empty spaces inside it.

Can Vova complete the wall using any amount of bricks (possibly zero)?

Input

The first line contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of parts in the wall.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the initial heights of the parts of the wall.

Output

Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).

Print "NO" otherwise.

Examples

input

Copy

52 1 1 2 5

output

Copy

YES

input

Copy

34 5 3

output

Copy

YES

input

Copy

210 10

output

Copy

YES

input

Copy

31 2 3

output

Copy

NO

Note

In the first example Vova can put a brick on parts 2 and 3 to make the wall [2,2,2,2,5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5,5,5,5,5].

In the second example Vova can put a brick vertically on part 3 to make the wall [4,5,5], then horizontally on parts 2 and 3 to make it [4,6,6][4,6,6] and then vertically on part 1 to make it [6,6,6].

In the third example the wall is already complete.

题解:如果相邻的两堆差值为2的倍数则可以成对消去,这个过程可以用栈来模拟,最后判断如果剩余堆的数量大于一,输出NO即可

代码:

#include
#include
#include
#include
#include
using namespace std;int main() { stack
s; int n; cin>>n; for(int t=0; t
1) cout<<"NO"<

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781894.html

你可能感兴趣的文章
php文件上传类
查看>>
CF219D Choosing Capital for Treeland
查看>>
luogu P3809 【模板】后缀排序
查看>>
Red Gate 破解
查看>>
JVM 调优工具
查看>>
SCTF 2014 pwn题目分析
查看>>
集合以及特殊集合
查看>>
USACO 2.2 Runaround Numbers
查看>>
利用 force index优化sql语句性能
查看>>
Matlab画图-非常具体,非常全面
查看>>
365. Water and Jug Problem
查看>>
SQL数据库数据检索top和distinct
查看>>
平衡搜索树--红黑树 RBTree
查看>>
sqlite驱动下载
查看>>
让IE6/IE7/IE8浏览器支持CSS3属性
查看>>
队列实现霍夫曼树
查看>>
【Java】图片高质量缩放类
查看>>
Python :类中设置默认属性并修改
查看>>
磁盘管理综合测试
查看>>
Unity3d Shader开发(三)Pass(Pass Tags,Name,BindChannels )
查看>>