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

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

 

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 (1n21051≤n≤2⋅105) — the number of parts in the wall.

The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1091≤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][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][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][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][6,6,6].

In the third example the wall is already complete.

代码:

#include 
using namespace std;int N;stack
s;int main() { scanf("%d", &N); for(int i = 0; i < N; i ++) { int x; scanf("%d", &x); if(s.empty()) s.push(x); else { if(abs(s.top() - x) % 2) s.push(x); else s.pop(); } } if(s.size() > 1) printf("NO\n"); else printf("YES\n"); return 0;}

  相邻的两个墙的高度差是 2 的倍数就可以了

转载于:https://www.cnblogs.com/zlrrrr/p/10184901.html

你可能感兴趣的文章
CODE[VS] 1842 递归第一次
查看>>
20180418小测
查看>>
数字三角形
查看>>
NGUI 减少drawcall规则
查看>>
三元表达,匿名函数
查看>>
前端笔记-基础笔记
查看>>
【LeetCode & 剑指offer刷题】查找与排序题6:33. Search in Rotated Sorted Array(系列)
查看>>
GNU/Linux超级本ZaReason Ultralap 440体验
查看>>
将github上托管的代码 在我的域名下运行
查看>>
【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize
查看>>
【codeforces 767A】Snacktower
查看>>
【MemSQL Start[c]UP 3.0 - Round 1 C】 Pie Rules
查看>>
Ognl中“%”、“#”、“$”详解
查看>>
我对应用软件——美团的看法
查看>>
执行了的程序,才是你的程序.
查看>>
struts2.x + Tiles2.x读取多个xml 配置文件
查看>>
表单校验之datatype
查看>>
python第六篇文件处理类型
查看>>
hdu 3183 A Magic Lamp 贪心
查看>>
ubuntu16系统磁盘空间/dev/vda1占用满的问题
查看>>