CODEFORCES-344D alternating current (simulated question)

Source: Internet
Author: User

codeforces-344dAlternating current
Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %i64d &%i64u

Submit Status

Description

Mad scientist Mike have just finished constructing a new device to search for extraterrestrial intelligence! He is in such a hurry to launch it's the first time that he plugged in the power wires without giving it a proper glanc E and started experimenting right away. After a while Mike observed, the wires ended up entangled and now has to be untangled again.

The device is powered by and wires "plus" and "minus". The wires run along the floor is from the wall (the "on" to the device). Both The wall and the device have both contacts in them on the same level, into which the wires is plugged in some order. The wires is considered entangled if there is one or more places where one wire runs above the other one. For example, the picture below have four such places (top view):

Mike knows the sequence in which and the wires run above each other. Mike also noticed that on the left side, the ' plus ' wire was always plugged to the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do. A wire can is freely moved and stretched on the floor, but cannot is cut.

To understand the problem better, read the notes to the test samples.

Input

The single line of the input contains a sequence of characters "+" and "-" of length n (1?≤ ? n? ≤?100000). The i-th (1?≤? I? ≤? n) position of the sequence contains the character "+", if on the I-th step from the Wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.

Output

Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if th E wires cannot be untangled.

Sample Input

Input
-++-
Output
Yes
Input
+-
Output
No
Input
++
Output
Yes
Input
-
Output
No

Hint

The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the ' plus ' wire lower, thus eliminating the ' crosses in the ', and then Draw it under the "minus" wire, eliminating also the remaining.

The second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus The wires cannot be untangled:

In the third testcase the ' plus ' wire simply runs above the ' minus ' wire twice in sequence. The wires can untangled by lifting "plus" and moving it higher:

In the fourth testcase the ' minus ' wire runs above the ' plus ' wire once. The wires cannot be untangled without moving the device itself:

Test Instructions Analysis:

The first is to provide two infinite wire, the middle of the two ends of the intersection, the picture is to give you a part, and both ends are positive, the following is always the negative, and then is to give you a series of strings, respectively, they are the cross part of the positive or negative on the top, and then from the first cross section to separate the wire Obviously if it is two consecutive for the same pole, then there is no intersection has no effect, because thinking can be found, if the same, can be the intersection of the part will be formed a negative and positive cross-section, if the same, the same can be pulled off the wire, so with a stack to maintain the results, If you encounter a different cross-section then press the stack, if you encounter the same cross-section as the top of the stack, the top element of the stack pops up.


#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue >using namespace Std;typedef long long LL; #define Lson RT << 1, L, Mid#define Rson RT << 1|1, Mid + 1, r#de Fine root 1, 1, nconst int maxn = 1e5 + 5;char Str[maxn];char stack[maxn];int main () {    scanf ("%s", str);    int top = 0;    int n = strlen (str);    for (int i = 0; I < N;i + +) {        if (top = = 0 | | stack[top]! = Str[i]) {            stack[++ top] = Str[i];        }        else-top;    }    if (top = = 0) printf ("yes\n");    else printf ("no\n");    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

CODEFORCES-344D alternating current (simulated question)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.