

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
行 列のグリッドがあります. あなたはグリッドの各マスに 以上 以下の整数を書き込み,以下の条件を満たしたいです.
- 左上のマスを出発し,右または下に隣接するマスへの移動を繰り返して,右下のマスへと至るパスを考える. ここで,通ったマス (始点終点を含む) に書かれた整数の総 が になるパスを,よいパスと呼ぶことにする.
- よいパスはちょうど つだけ存在し,それは文字列 が表すパスである.
文字列 が表すパスとは,各 () について, 回目の移動の際, の 文字目が
R
なら右,D
なら下に進むようなパスである.
条件を満たす整数の書き込み方が存在するかどうか判定してください.
つの入力ファイルにつき, 個のテストケースを解いてください.
ビット単位 演算とは
非負整数 のビット単位 、 は、以下のように定義されます。
- を二進表記した際の () の位の数は、 を二進表記した際の の位の数のうち一方のみが であれば 、そうでなければ である。
一般に 個の非負整数 のビット単位 は と定義され、これは の順番によらないことが証明できます。
制約
- はちょうど 個の
D
と 個のR
からなる文字列 - 入力される数はすべて整数
入力
入力は以下の形式で標準入力から与えられる.
各ケースは以下の形式で与えられる.
出力
各ケースに対し,条件を満たす整数の書き込み方が存在する場合は Yes
を,存在しないならば No
を出力せよ.
出力中の各文字は英大文字・小文字のいずれでもよい.
入力例 1Copy
4 2 2 1 RD 4 3 1 RDDDR 15 20 18 DDRRRRRRRDDDDRRDDRDRRRRDDRDRDDRRR 20 15 7 DRRDDDDDRDDDRRDDRRRDRRRDDDDDRRRDD
出力例 1Copy
Yes No Yes No
例えば ケース目については,以下のようなグリッドを作れば良いです.
11 00
Score : points
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.
Generally, the bitwise of non-negative integers is defined as , 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 1Copy
4 2 2 1 RD 4 3 1 RDDDR 15 20 18 DDRRRRRRRDDDDRRDDRDRRRRDDRDRDDRRR 20 15 7 DRRDDDDDRDDDRRDDRRRDRRRDDDDDRRRDD
Sample Output 1Copy
Yes No Yes No
As an example, for the first case, you can make the grid as follows.
11 00