atcoder#ARC119D. [ARC119D] Grid Repainting 3
[ARC119D] Grid Repainting 3
Score: points
Problem Statement
We have a canvas represented as a grid with rows and columns. Let denote the square at the -th row from the top and -th column from the left . Initially, is painted red if R
and blue if B
.
For any number of times, you can choose one of the two operations below and do it.
Operation X: Choose a square painted red, and repaint all squares in the row containing that square (including itself) white. Operation Y: Choose a square painted red, and repaint all squares in the column containing that square (including itself) white.
Show one way that maximizes the number of squares painted white in the end.
Constraints
- is
R
orB
. - and are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the following to Standard Output:
Here, is the number of operations you do, and means that your -th operation is Operation with being chosen, where is X
or Y
.
If there are multiple possible solutions, you may print any of them.
4 4
RBBB
BBBB
BBBB
RBRB
3
X 1 1
Y 4 3
X 4 1
Here is one sequence of operations that makes squares white:
- First, do Operation X choosing .
- Then, do Operation Y choosing .
- Then, do Operation X choosing .
There is no way to make or more squares white.
1 119
BBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBB
4
Y 1 60
Y 1 109
Y 1 46
X 1 11
We can repaint all squares white.
10 10
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
0
Since there is no red square, we cannot do the operations at all.