CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)
http://codeforces.com/contest/1092/problem/D1
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)?
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.
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).
Print "NO" otherwise.
5
2 1 1 2 5
YES
3
4 5 3
YES
2
10 10
YES
3
1 2 3
NO
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 <bits/stdc++.h>
using namespace std; int N;
stack<int> 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 的倍数就可以了
CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)的更多相关文章
- CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)
http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...
- Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...
- CodeForces Round #527 (Div3) B. Teams Forming
http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...
- CodeForces Round #527 (Div3) C. Prefixes and Suffixes
http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...
- CodeForces Round #527 (Div3) A. Uniform String
http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...
- D1. Great Vova Wall (Version 1)
链接 [https://codeforces.com/contest/1092/problem/D1] 题意 给你n个位置墙的高度,现在你有2×1 砖块,你可以竖直或者水平放置 问你是否可以使得所有位 ...
- Codeforces Round #602 Div2 D1. Optimal Subsequences (Easy Version)
题意:给你一个数组a,询问m次,每次返回长度为k的和最大的子序列(要求字典序最小)的pos位置上的数字. 题解:和最大的子序列很简单,排个序就行,但是题目要求字典序最小,那我们在刚开始的时候先记录每个 ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #527 (Div. 3)
一场div3... 由于不计rating,所以打的比较浪,zhy直接开了个小号来掉分,于是他AK做出来了许多神仙题,但是在每一个程序里都是这么写的: 但是..sbzhy每题交了两次,第一遍都是对的,结 ...
随机推荐
- 怎样在windows上定时执行python脚本
作为一个需要在电脑上工作和学习的人,一件十分困扰我的事情就是怎样不受互联网中其他内容的干扰而专注于自己想要做的事情,有的时候真的是沉浸于微博上的消息,忘了自己本来想要做的事.不过我有一件神器,自己爱豆 ...
- 什么是PHP7中的孤儿进程与僵尸进程
什么是PHP7中的孤儿进程与僵尸进程 基本概念 我们知道在unix/linux中,正常情况下,子进程是通过父进程创建的,子进程在创建新的进程.子进程的结束和父进程的运行是一个异步过程,即父进程永远无法 ...
- 安装虚拟机及学习linux系统 20155222卢梓杰
安装虚拟机及学习linux系统 20155222卢梓杰 首先按照要求下载virtualbox,没有遇到问题. 接下来新建一个虚拟机,按照要求应当安装乌班图64,这里只有32位的.在网上搜寻了许久,终于 ...
- 20155239 2016-2017-2 《Java程序设计》第10周学习总(2017-04-22 16:26
教材学习 1.基本概念划分 OIS的七层协议: 应用层.表示层.会话层.运输层.网络层.数据链路层.物理层. OIS的五层协议: 应用层.运输层.网络层.数据链路层.物理层. 由下往上介绍如下: 2. ...
- # 2017-2018-1 20155336《信息安全技术》实验二——Windows口令破解
2017-2018-1 20155336<信息安全技术>实验二——Windows口令破解 实验原理 口令破解方法 口令破解主要有两种方法:字典破解和暴力破解. 字典破解是指通过破解者对管理 ...
- WPF中使用WindowChrome自定义窗口中遇到的最大化问题
FrameWork 4.5 之后,内置了WindowChrome类,官方文档: https://msdn.microsoft.com/en-us/library/system.windows.shel ...
- SupperSocket深入浅出
这篇文章出要是SuperSocket底层如何接收数据 Process(ArraySegment<byte> segment) 获取加载数据(直到数据全部接收后返回) namespace S ...
- day 14 元组
1. 使用场景? # 列表list 数据类型相同, #rwx文件 100个人的名字, # 用字典 dict ['dɪkt] 很多信息描述1个人, # tuple [ˈtʌpəl] #只读文件 不能修改 ...
- day2 CSS- 选择器
1.CSS 语法 css是英文Cascading Style Sheets的缩写,称为层叠样式表 2.css的四种引入方式 1.行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现 ...
- qbxt的题:运
运 题意: 包含4,7的数成为幸运数.给一个序列,求多少个长度为k子序列满足:不包含两个及以上的相同的幸运数.(4出现两次就是不合法的,而4,7各出现一次是合法的). 分析: 1e9内幸运数只有2^1 ...