#abc297b. B - chess960

B - chess960

Score : 200200 points

问题陈述

高桥正在玩一个名为 Chess960 的游戏。他决定编写一段代码来判断一个随机初始状态是否满足 Chess960 的条件。

给定一个长度为八的字符串 SS,其中 SS 包含恰好一个 K 和一个 Q,以及恰好两个 R、两个 B 和两个 N。请确定 SS 是否满足以下所有条件:

  • 假设从左起第 xx 个和第 yy 个字符(x<yx < y)均为 B,则 xxyy 的奇偶性不同。

  • K 在两个 R 之间。更形式化地表述,假设从左起第 xx 个和第 yy 个字符(x<yx < y)为 R,而第 zz 个字符为 K;那么应有 x<z<yx < z < y

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi is playing a game called Chess960. He has decided to write a code that determines if a random initial state satisfies the conditions of Chess960.

You are given a string SS of length eight. SS has exactly one K and Q, and exactly two R's, B's , and N's. Determine if SS satisfies all of the following conditions.

  • Suppose that the xx-th and yy-th (x<y)(x < y) characters from the left of SS are B; then, xx and yy have different parities.

  • K is between two R's. More formally, suppose that the xx-th and yy-th (x<y)(x < y) characters from the left of SS are R and the zz-th is K; then x<z<yx< z < y.

Constraints

  • SS is a string of length 88 that contains exactly one K and Q, and exactly two R's, B's , and N's.

Input

The input is given from Standard Input in the following format:

SS

Output

Print Yes if SS satisfies the conditions; print No otherwise.

Sample Input 1

RNBQKBNR

Sample Output 1

Yes

The 33-rd and 66-th characters are B, and 33 and 66 have different parities. Also, K is between the two R's. Thus, the conditions are fulfilled.

Sample Input 2

KRRBBNNQ

Sample Output 2

No

K is not between the two R's.

Sample Input 3

BRKRBQNN

Sample Output 3

No

update @ 2024/3/10 12:19:58