#P7338. Domino Coloring

    ID: 20536 Type: Default 1000ms 256MiB

Domino Coloring

Domino Coloring

A 2×n grid is initially all white. In each move, you may choose two adjacent (sharing a side) white cells and color one red and the other blue. Given a target configuration where some cells are specified to be red (and the remaining cells can be in any color), determine whether it is possible to obtain a configuration in which all the specified cells are red by performing an arbitrary number of such moves.

In each move, note that the two cells chosen must both be white, and you are free to choose which one becomes red and which one becomes blue. However, you cannot color an already colored cell. In particular, observe that if two required red cells are adjacent, they cannot be colored in the same move (since that would yield one red and one blue), so they must be colored in two separate moves with two distinct partners. Essentially, the problem reduces to whether every required red cell can be paired with an adjacent cell that is not required to be red (so that the required cell can be colored red and its partner blue) without reusing a cell in more than one move.

The grid cells are indexed by row (1 or 2) and column (1 through n). Two cells are adjacent if and only if they share a common side (that is, horizontally or vertically adjacent).

inputFormat

The first line contains a single integer n (1 ≤ n ≤ 105, for example), the number of columns. The following two lines each contain a string of length n. The characters in these strings are either 'R' or '.', where 'R' indicates that the corresponding cell (in row 1 for the first line and row 2 for the second line) is required to be red, and '.' means there is no requirement on that cell.

Note: It is guaranteed that all characters are either 'R' or '.'.

outputFormat

Output a single line containing either YES if it is possible to achieve the configuration by a sequence of valid moves, or NO otherwise.

sample

3
R.R
...
YES

</p>