[BOJ 14515] Yin and Yang Stones

View as PDF

Submit solution

Points: 2
Time limit: 2.0s
Memory limit: 512M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

A mysterious circular arrangement of black stones and white stones has appeared. Ming has been tasked with balancing the stones so that only one black and one white stone remain.</p>

Ming has two operations for balancing the stones:

  1. Take some consecutive sequence of stones where there is exactly one more black stone than a white stone and replace the stones with a single black stone
  2. Take some consecutive sequence of stones where there is exactly one more white stone than black stone and replace the stones with a single white stone

Given a circular arrangement, determine if it is possible for Ming to balance the stones.

입력 형식

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The input will consist of a single string s (1 ≤ |s| ≤ 105), with only the characters capital ‘B’ and ‘W’. The stones are arranged in a circle, so the first stone and the last stone are adjacent.

출력 형식

Output 1 if it is possible for Ming to balance the stones with his rules. Otherwise, output 0.

예제 입력 1

WWBWBB

예제 출력 1

1

예제 입력 2

WWWWBBW

예제 출력 2

0

예제 입력 3

WBBBBBWWBW

예제 출력 3

0

Comments

There are no comments at the moment.