#P7338. 『MdOI R4』Color

『MdOI R4』Color

Description

Student M has a grid paper with 22 rows and nn columns. At the beginning, all cells are white.

She decides to color some cells. Specifically, each time she chooses two adjacent (4-connected, i.e., sharing a common edge) white cells, colors one of them red, and the other blue.

Her goal is to make some specified cells become red through any number of operations, with no requirements on the other cells. Please help her determine whether the goal can be achieved using the operations above.

Input Format

This problem contains multiple test cases. The first line contains a positive integer TT, the number of test cases.

Then there are TT test cases, each consisting of three lines:

  • The first line contains a positive integer nn, the number of columns of the grid paper.
  • The second line contains a 01 string p1np_{1\ldots n}, where pi=1p_i=1 means the cell in row 11, column ii must be red; otherwise there is no requirement.
  • The third line contains a 01 string q1nq_{1\ldots n}, where qi=1q_i=1 means the cell in row 22, column ii must be red; otherwise there is no requirement.

Output Format

Output TT lines, one for each test case.

For each test case, if it is possible, output RP; otherwise output ++.

3
5
01110
10010
5
11000
01100
5
00101
10100

RP
++
RP

Hint

[Sample Explanation]

temp.png

In the figure above, the left side shows one possible solution for the first test case, and the right side shows one possible solution for the third test case. For the second test case, there is no solution that satisfies the requirements.

[Constraints and Notes]

This problem uses bundled tests.

Subtask ID nn\le Special Property TT\le Score
11 33 No special restrictions 1010 1010
22 1010 2020
33 No special restrictions All 11 are in the same row 11
44 The number of 11 does not exceed 44 1313
55 10310^3 No special restrictions 2525
66 No special restrictions 3030
77 1616 6553665536 11

For all test cases, 1n1051\le n\le 10^5 and n220\sum n\le 2^{20}.

Translated by ChatGPT 5