## UTS Open '18 P5 - Room 666

View as PDF

Points: 25 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Some UTS students want to sneak in to the mythical Room 666, where it is rumored that the report cards are kept. However, the teachers have devised an complex lock system to prevent students from opening the door. The lock consists of many switches arranged in a diamond shape like this:

Sample Input 1

Some switches are set to open (), while others are set to closed (). In order to unlock the door, all switches must be set to open. The students can flip any switch they want (changing its value from to , or from to ), and they can do this at most times. However, when a switch is flipped, all switches in the same row or column get flipped too. The students are puzzled by this elaborate contraption, so they ask you to unlock it! For the sake of these students' grades, help them find a sequence of flips that will unlock the door.

#### Input Specification

The first line contains the even integer , the height and width of the diamond-shaped lock. The next lines contain characters each: either a 0 (an open switch), 1 (closed switch), or . (no switch).

#### Output Specification

Output any sequence of flips that will unlock the door as follows: on the first line, print , the number of flips in your sequence. On the next lines, print two integers , , indicating that the switch in row , column should be flipped (along with the other switches in row or column ). The rows and columns are -indexed, with the top-left position being and the bottom-right position being . It is guaranteed that such a sequence exists - otherwise, even the teachers wouldn't be able to enter the room!

#### Sample Input 1

8
...10...
..0110..
.011010.
11101011
00110100
.100111.
..1101..
...10...

#### Sample Output 1

3
2 4
6 6
4 3

#### Explanation for Sample Output 1

Here is one possible sequence of flips:

Note that there are multiple solutions, and any solution that requires flips or less will be accepted.

#### Sample Input 2

2
10
01

#### Sample Output 2

2
1 1
2 2