#P10554. Kitty's Light Switching Challenge
Kitty's Light Switching Challenge
Kitty's Light Switching Challenge
Kitty has lights arranged in an matrix. Some of these lights are on and some are off. Kitty can perform three types of operations:
- Choose a row and reverse the state of every light in that row.
- Choose a column and reverse the state of every light in that column.
- Choose exactly one light and reverse its state; this operation can be used at most times.
The goal is to turn off all the lights using at most operations. The operations should be output in the following format (using 1-indexed positions):
- Row reversal:
R i
(toggles row ) - Column reversal:
C j
(toggles column ) - Single light toggle:
L i j
(toggles the light at row , column )
If a valid sequence exists that satisfies the constraints (i.e. the number of single light toggles does not exceed , and the total number of operations is at most ), output the number of operations used followed by the list of operations. Otherwise, output -1.
inputFormat
The first line contains two integers and , denoting the size of the matrix and the maximum number of individual light toggles allowed.\nEach of the following lines contains integers (each 0 or 1), representing the state of the lights (0 for off, 1 for on).
outputFormat
If a valid sequence of operations exists, first output an integer , the total number of operations performed. Then output lines, each describing one operation in the order they are performed. If no valid sequence exists, output -1.
sample
2 2
0 1
1 0
2
R 2
C 2
</p>