#agc060b. [agc060_b]Unique XOR Path
[agc060_b]Unique XOR Path
Problem Statement
We have a grid with rows and columns. You want to write an integer between and in each square in the grid to satisfy the following condition.
- Consider a path that starts at the top-left square, repeatedly moves right or down to an adjacent square, and ends at the bottom-right square. Such a path is said to be good if and only if the total of the integers written on the squares visited (including the starting and ending points) is .
- There is exactly one good path, which is the path represented by a string . The path represented by the string is a path that, for each (), the -th move is right if the -th character of is
R
and down if that character isD
.
Determine whether there is a way to write integers that satisfies the condition.
For each input file, solve test cases.
What is bitwise ?
The bitwise of non-negative integers and , , is defined as follows.
- When is written in binary, the -th lowest bit () is if exactly one of the -th lowest bits of and is , and otherwise.
For instance, (in binary: ).
Generally, the bitwise of non-negative integers is defined as $(\\dots ((p_1 \\oplus p_2) \\oplus p_3) \\oplus \\dots \\oplus p_k)$, which can be proved to be independent of the order of .
Constraints
- is a string containing exactly
D
s andR
s. - All numbers in the input are integers.
Input
The input is given from Standard Input in the following format:
Each case is in the following format:
Output
For each case, print Yes
if there is a way to write integers that satisfies the condition, and No
otherwise. Each character in the output may be either uppercase or lowercase.
Sample Input 1
4
2 2 1
RD
4 3 1
RDDDR
15 20 18
DDRRRRRRRDDDDRRDDRDRRRRDDRDRDDRRR
20 15 7
DRRDDDDDRDDDRRDDRRRDRRRDDDDDRRRDD
Sample Output 1
Yes
No
Yes
No
As an example, for the first case, you can make the grid as follows.
11
00