Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
無限に長いピアノの鍵盤があります。 この鍵盤内の連続する区間であって、白鍵 W 個と黒鍵 B 個からなるものは存在しますか?
文字列 wbwbwwbwbwbw
を無限に繰り返してできる文字列を S とおきます。
S の部分文字列であって、W 個の w
と B 個の b
からなるものは存在しますか?
S の部分文字列とは
S の部分文字列とは、ある 2 つの正整数 l,r\ (l\leq r) に対して、S の l 文字目、l+1 文字目、\dots、r 文字目をこの順に繋げてできる文字列のことをいいます。制約
- W,B は整数
- 0\leq W,B \leq 100
- W+B \geq 1
入力
入力は以下の形式で標準入力から与えられる。
W B
出力
S の部分文字列であって、W 個の w
と B 個の b
からなるものが存在するならば Yes
を、存在しないならば No
を出力せよ。
入力例 1
3 2
出力例 1
Yes
S の最初の 15 文字は wbwbwwbwbwbwwbw
であり、S の 11 文字目から 15 文字目までを取り出してできる文字列 bwwbw
は 3 個の w
と 2 個の b
からなる部分文字列の一例です。
入力例 2
3 0
出力例 2
No
3 個の w
と 0 個の b
からなる文字列は www
のみですが、これは S の部分文字列ではありません。
入力例 3
92 66
出力例 3
Yes
Score: 200 points
Problem Statement
There is an infinitely long piano keyboard. Is there a continuous segment within this keyboard that consists of W white keys and B black keys?
Let S be the string formed by infinitely repeating the string wbwbwwbwbwbw
.
Is there a substring of S that consists of W occurrences of w
and B occurrences of b
?
What is a substring of S?
A substring of S is a string that can be formed by concatenating the l-th, (l+1)-th, \dots, r-th characters of S in this order for some two positive integers l and r (l\leq r).Constraints
- W and B are integers.
- 0\leq W,B \leq 100
- W+B \geq 1
Input
The input is given from Standard Input in the following format:
W B
Output
If there is a substring of S that consists of W occurrences of w
and B occurrences of b
, print Yes
; otherwise, print No
.
Sample Input 1
3 2
Sample Output 1
Yes
The first 15 characters of S are wbwbwwbwbwbwwbw
. You can take the 11-th through 15-th characters to form the string bwwbw
, which is a substring consisting of three occurrences of w
and two occurrences of b
.
Sample Input 2
3 0
Sample Output 2
No
The only string consisting of three occurrences of w
and zero occurrences of b
is www
, which is not a substring of S.
Sample Input 3
92 66
Sample Output 3
Yes