CF1092D1.Great Vova Wall (Version 1)
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 a of n integers, with ai being the height of the i-th part of the wall.
Vova can only use 2×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 i the current height of part i is the same as for part i+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 1 of the wall or to the right of part n 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)?
沃瓦的家族正在建造“伟大的沃瓦墙”(由沃瓦本人命名)。沃瓦的父母、祖父母、曾祖父母都为此墙做出了贡献。如今,最后的收尾工作完全交由沃瓦来完成。
当前墙体的状态可表示为一个长度为 n 的整数序列 a,其中 ai 表示墙体第 i 段的高度。
沃瓦只能使用 2×1 的砖块来砌墙(他拥有无限供应的此类砖块)。
沃瓦可以将砖块水平放置在墙体相邻且高度相等的两段上。这意味着:若对某个 i,当前第 i 段与第 i+1 段的高度相同,则沃瓦可在该处放置一块砖,从而使这两段的高度均增加 1。显然,沃瓦不能以致使砖块部分超出墙体边界的方式放置砖块(即不能置于墙体第 1 段左侧或第 n 段右侧)。
下一段内容仅适用于本题版本 1。
沃瓦还可以将砖块竖直放置。这意味着:可将墙体任意一段的高度增加 2。
沃瓦是一位完美主义者,因此他认为墙体完工当且仅当满足以下两个条件:
- 墙体所有段的高度均相同;
- 墙体内部不存在空隙。
沃瓦能否通过使用任意数量(可能为零)的砖块完成墙体?
输入格式
The first line contains a single integer n (1≤n≤2⋅105) — the number of parts in the wall.
The second line contains n integers a1,a2,…,an (1≤ai≤109) — the initial heights of the parts of the wall.
第一行包含一个整数 n(1≤n≤2⋅105)—— 墙的段数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 墙各段的初始高度。
输出格式
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
如果沃瓦可以使用任意数量(可能为零)的砖块完成这面墙,则输出 “YES”。
否则,输出 “NO”。
输入输出样例
输入#1
5 2 1 1 2 5
输出#1
YES
输入#2
3 4 5 3
输出#2
YES
输入#3
2 10 10
输出#3
YES
输入#4
3 1 2 3
输出#4
NO
说明/提示
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] and then vertically on part 1 to make it [6,6,6].
In the third example the wall is already complete.
在第一个例子中,沃瓦可以在第 2 和第 3 部分各放置一块砖,使墙变为 [2,2,2,2,5];然后在第 1 和第 2 部分各放置 3 块砖,在第 3 和第 4 部分也各放置 3 块砖,最终使墙变为 [5,5,5,5,5]。
在第二个例子中,沃瓦可以先在第 3 部分竖直放置一块砖,使墙变为 [4,5,5];再在第 2 和第 3 部分水平放置一块砖,使墙变为 [4,6,6];最后在第 1 部分竖直放置一块砖,使墙变为 [6,6,6]。
在第三个例子中,墙已经完工。
输入解题思路,AI测评打分。不知道怎么写?