CF1218I.The Light Square
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For her birthday Alice received an interesting gift from her friends – The Light Square. The Light Square game is played on an N×N lightbulbs square board with a magical lightbulb bar of size N×1 that has magical properties. At the start of the game some lights on the square board and magical bar are turned on. The goal of the game is to transform the starting light square board pattern into some other pattern using the magical bar without rotating the square board. The magical bar works as follows:
It can be placed on any row or column
The orientation of the magical lightbulb must be left to right or top to bottom for it to keep its magical properties
The entire bar needs to be fully placed on a board
The lights of the magical bar never change
If the light on the magical bar is the same as the light of the square it is placed on it will switch the light on the square board off, otherwise it will switch the light on
The magical bar can be used an infinite number of times
Alice has a hard time transforming her square board into the pattern Bob gave her. Can you help her transform the board or let her know it is impossible? If there are multiple solutions print any.
输入格式
The first line contains one positive integer number N (1≤N≤2000) representing the size of the square board.
The next N lines are strings of length N consisting of 1's and 0's representing the initial state of the square board starting from the top row. If the character in a string is 1 it means the light is turned on, otherwise it is off.
The next N lines are strings of length N consisting of 1's and 0's representing the desired state of the square board starting from the top row that was given to Alice by Bob.
The last line is one string of length N consisting of 1's and 0's representing the pattern of the magical bar in a left to right order.
输出格式
Transform the instructions for Alice in order to transform the square board into the pattern Bob gave her. The first line of the output contains an integer number M (0≤M≤105 ) representing the number of times Alice will need to apply the magical bar.
The next M lines are of the form "col X " or "row X ", where X is 0 -based index of the matrix, meaning the magical bar should be applied to either row X or column X . If there is no solution, print only -1. In case of multiple solutions print any correct one.
输入输出样例
输入#1
2 11 11 00 01 11
输出#1
-1
输入#2
2 10 00 00 00 10
输出#2
1 row 0
输入#3
3 110 011 100 100 011 100 100
输出#3
3 row 0 col 0 col 1
说明/提示
Example 1: It is impossible to transform square board from one format to another
Example 2: Magic bar can be applied on first row or column.