#P10554. Kitty's Light Switching Challenge

    ID: 12574 Type: Default 1000ms 256MiB

Kitty's Light Switching Challenge

Kitty's Light Switching Challenge

Kitty has n2n^2 lights arranged in an n×nn \times n matrix. Some of these lights are on and some are off. Kitty can perform three types of operations:

  1. Choose a row and reverse the state of every light in that row.
  2. Choose a column and reverse the state of every light in that column.
  3. Choose exactly one light and reverse its state; this operation can be used at most kk times.

The goal is to turn off all the lights using at most 3n3n operations. The operations should be output in the following format (using 1-indexed positions):

  • Row reversal: R i (toggles row ii)
  • Column reversal: C j (toggles column jj)
  • Single light toggle: L i j (toggles the light at row ii, column jj)

If a valid sequence exists that satisfies the constraints (i.e. the number of single light toggles does not exceed kk, and the total number of operations is at most 3n3n), output the number of operations used followed by the list of operations. Otherwise, output -1.

inputFormat

The first line contains two integers nn and kk, denoting the size of the matrix and the maximum number of individual light toggles allowed.\nEach of the following nn lines contains nn 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 mm, the total number of operations performed. Then output mm 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>