B - Unique XOR Path Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 700700

問題文

NNMM 列のグリッドがあります. あなたはグリッドの各マスに 00 以上 2K12^K-1 以下の整数を書き込み,以下の条件を満たしたいです.

  • 左上のマスを出発し,右または下に隣接するマスへの移動を繰り返して,右下のマスへと至るパスを考える. ここで,通ったマス (始点終点を含む) に書かれた整数の総 XOR\mathrm{XOR}00 になるパスを,よいパスと呼ぶことにする.
  • よいパスはちょうど 11 つだけ存在し,それは文字列 SS が表すパスである. 文字列 SS が表すパスとは,各 ii (1iN+M21 \leq i \leq N+M-2) について,ii 回目の移動の際,SSii 文字目が R なら右,D なら下に進むようなパスである.

条件を満たす整数の書き込み方が存在するかどうか判定してください.

11 つの入力ファイルにつき,TT 個のテストケースを解いてください.

ビット単位 XOR\mathrm{XOR} 演算とは

非負整数 A,BA, B のビット単位 XOR\mathrm{XOR}ABA \oplus B は、以下のように定義されます。

  • ABA \oplus B を二進表記した際の 2k2^k (k0k \geq 0) の位の数は、A,BA, B を二進表記した際の 2k2^k の位の数のうち一方のみが 11 であれば 11、そうでなければ 00 である。
例えば、35=63 \oplus 5 = 6 となります (二進表記すると: 011101=110011 \oplus 101 = 110)。
一般に kk 個の非負整数 p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k のビット単位 XOR\mathrm{XOR}(((p1p2)p3)pk)(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k) と定義され、これは p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k の順番によらないことが証明できます。

制約

  • 1T1001 \leq T \leq 100
  • 2N,M302 \leq N,M \leq 30
  • 1K301 \leq K \leq 30
  • SS はちょうど N1N-1 個の DM1M-1 個の R からなる文字列
  • 入力される数はすべて整数

入力

入力は以下の形式で標準入力から与えられる.

TT
case1case_1
case2case_2
\vdots
caseTcase_T

各ケースは以下の形式で与えられる.

NN MM KK
SS

出力

各ケースに対し,条件を満たす整数の書き込み方が存在する場合は Yes を,存在しないならば No を出力せよ. 出力中の各文字は英大文字・小文字のいずれでもよい.


入力例 1Copy

Copy
4
2 2 1
RD
4 3 1
RDDDR
15 20 18
DDRRRRRRRDDDDRRDDRDRRRRDDRDRDDRRR
20 15 7
DRRDDDDDRDDDRRDDRRRDRRRDDDDDRRRDD

出力例 1Copy

Copy
Yes
No
Yes
No

例えば 11 ケース目については,以下のようなグリッドを作れば良いです.

11
00

Score : 700700 points

Problem Statement

We have a grid with NN rows and MM columns. You want to write an integer between 00 and 2K12^K-1 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 XOR\mathrm{XOR} of the integers written on the squares visited (including the starting and ending points) is 00.
  • There is exactly one good path, which is the path represented by a string SS. The path represented by the string SS is a path that, for each ii (1iN+M21 \leq i \leq N+M-2), the ii-th move is right if the ii-th character of SS is R and down if that character is D.

Determine whether there is a way to write integers that satisfies the condition.

For each input file, solve TT test cases.

What is bitwise XOR\mathrm{XOR}?

The bitwise XOR\mathrm{XOR} of non-negative integers AA and BB, ABA \oplus B, is defined as follows.

  • When ABA \oplus B is written in binary, the kk-th lowest bit (k0k \geq 0) is 11 if exactly one of the kk-th lowest bits of AA and BB is 11, and 00 otherwise.
For instance, 35=63 \oplus 5 = 6 (in binary: 011101=110011 \oplus 101 = 110).
Generally, the bitwise XOR\mathrm{XOR} of kk non-negative integers p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k is defined as (((p1p2)p3)pk)(\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 p1,p2,p3,,pkp_1, p_2, p_3, \dots, p_k.

Constraints

  • 1T1001 \leq T \leq 100
  • 2N,M302 \leq N,M \leq 30
  • 1K301 \leq K \leq 30
  • SS is a string containing exactly N1N-1 Ds and M1M-1 Rs.
  • All numbers in the input are integers.

Input

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

TT
case1case_1
case2case_2
\vdots
caseTcase_T

Each case is in the following format:

NN MM KK
SS

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

Copy
4
2 2 1
RD
4 3 1
RDDDR
15 20 18
DDRRRRRRRDDDDRRDDRDRRRRDDRDRDDRRR
20 15 7
DRRDDDDDRDDDRRDDRRRDRRRDDDDDRRRDD

Sample Output 1Copy

Copy
Yes
No
Yes
No

As an example, for the first case, you can make the grid as follows.

11
00


2025-04-05 (Sat)
23:45:46 +00:00