1. 程式人生 > >CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)

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 

a">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 

i">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 
n">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:

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
5
2 1 1 2 5
output Copy
YES
input Copy
3
4 5 3
output Copy
YES
input Copy
2
10 10
output Copy
YES
input Copy
3
1 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 <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)

http://codeforces.com/contest/1092/problem/D1   Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparen

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 by Vova himself). Vova's parents, grandparen

Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1)

題目: 傳送門 題意: 給出一個2*1的磚塊,有兩種放磚塊的操作,一種是橫著放,這樣會使相鄰的兩塊牆高度加1,一種是豎著放,這樣會使牆高度加2,問以上兩種操作是否可以使建成的牆高度相同,並且建成的牆沒有空隙。 思路: 因為每塊牆可以通過無限次數的豎著放達到最接近相鄰牆的高度,所以真正影響

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 test 2 seconds memory limit p

Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) (棧)

題目連結:http://codeforces.com/contest/1092/problem/D1 題意:是有n個列,然後輸入n個數ai表示每個列當前的磚的個數,然後有任意塊2*1和1*2的磚,問最後能不能鋪滿n*max(ai) 思路:如果相鄰的兩堆差值為2的倍數則可以成對消去,用棧模

D1. Great Vova Wall (Version 1)

連結 [https://codeforces.com/contest/1092/problem/D1] 題意 給你n個位置牆的高度,現在你有2×1 磚塊,你可以豎直或者水平放置 問你是否可以使得所有位置高度一樣 思路 都在程式碼裡,看了你就恍然大悟了。。。仔細想想 程式碼 #include<

D1. Great Vova Wall (Version 1) (思維)

題目連結:https://codeforces.com/contest/1092/problem/D1 題意:給你n個ai,ai表示第i堵牆的高度,現在都一個1*2的磚頭,問:能否把這片牆砌成高度一直的牆? 題解:一般問你YES or NO 的問題,就不用想太複雜,直接推理一下就好。

CodeForces - 1092D1 Great Vova Wall (Version 1) 思維 棧

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 to

Great Vova Wall (Version 1)

https://codeforces.com/contest/1092/problem/D1 /* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #inc

Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思維】

傳送門:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per test 2 seconds memory limit p

Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) (棧)

題意:有n個列,然後輸入n個數ai表示每個列當前的磚的個數,然後只有有1*2的磚,問最後能不能鋪滿n*max(ai) 思路:由於只能用1*2的磚,所以只有兩塊磚的高度相同時才可以消去,還有就是像這樣的1221不滿足題意,因為兩邊的相同的高度沒法合在一起,像這樣的2112這種才滿足,最後可以有

CF1092(div3):Great Vova Wall (棧)(還不錯)

D1. Great Vova Wall (Version 1): 題意:給定長度為N的牆,以及每個位置的一些高度,現在讓你用1*2的磚和2*1的磚去鋪,問最後能否鋪到高度一樣。 思路:分析其奇偶性,在一個位置加1*2的磚,其奇偶性不變。在相鄰的而且高度相同的位置加2*1的磚,兩個奇偶行都改變。那麼我們不需

CodeForces Round #527 (Div3) B. Teams Forming

http://codeforces.com/contest/1092/problem/B   There are nn students in a university. The number of students is even. The ii-th 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 string ss of length nn cons

CodeForces - 1092D2 Great Vova Wall (Version 2) 思維 棧

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 to

Great Vova Wall (Version 2)

https://codeforces.com/contest/1092/problem/D2 /* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #inc

Codeforces Round #527 (Div. 3) 總結 A B C D1 D2 F

傳送門 A 貪心的取 每個字母n/k次 令r=n%k 讓前r個字母各取一次 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 #define rep(i, a, b) f

CodeForces Round #498 div3

命令 col 對稱 stdout add 完全 最大的 其他 const A: 題目沒讀, 啥也不會的室友幫我寫的。 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define Fopen fr

Codeforces Round #515 (Div. 3)A. Vova and Train【水題】

A. Vova and Train time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vova

Codeforces Round #515 (Div. 3) A. Vova and Train

題解 題目大意 總長度為L 每到v的倍數位置都有一個路燈 現有一火車在[l, r]問在火車遮擋後 能看見多少個路燈 (r - 1) / v計算左側出現路燈數量L / v - r / v計算右側出現路燈數量 AC 程式碼 #include <stdio.h&