103461: [Atcoder]ABC346 B - Piano

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:21 Solved:0

Description

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

Input

Output

得分:200分

问题描述

有一个无限长的钢琴键盘。 这个键盘中是否存在一个连续的片段,由$W$个白键和$B$个黑键组成?

令$S$是由无限重复字符串wbwbwwbwbwbw形成的字符串。

是否存在$S$的一个子串,由$W$个w和$B$个b组成?

什么是$S$的子串? $S$的子串是可以通过将$S$中的第$l$个、第$(l+1)$个、$\dots$、第$r$个字符按顺序连接起来形成的字符串,其中$l$和$r$是两个正整数,且$l\leq 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。你可以取第11个到第15个字符形成字符串bwwbw,这是一个由三个w和两个b组成的子串。


样例输入2

3 0

样例输出2

No

由三个w和零个b组成的唯一字符串是www,它不是$S$的子串。


样例输入3

92 66

样例输出3

Yes

加入题单

上一题 下一题 算法标签: