306592: CF1218I. The Light Square

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

The Light Square

题意翻译

## 题目描述 爱丽丝在她的生日那天收到了朋友们送她的一件有趣的礼物——光明方板。光明方板游戏是在一个n×n灯泡方板上玩的,方板上有一个n×1大小的具有魔法属性的魔法灯棒。游戏开始时,方块板和魔法棒上的一些灯都会亮起。这个游戏的目标是在不旋转方板的情况下,使用魔法棒将起始方板图案转换成其他图案。神奇魔法棒的工作原理如下: 它可以放在任何行或列上 魔法棒的方向必须从左到右或从上到下,这样才能保持其魔法特性 整根魔法棒都要放在方板上 魔法棒的灯光永不改变 如果魔法棒上的灯和方板上的灯的状态是一样的,它会把方板上的灯关掉,否则它会把灯打开 魔法棒可以无限次使用 爱丽丝很难把她的方板变成鲍勃给她的式样。你能帮她把方板上的灯改变成想要的样子或者让她知道这是不可能的么?如果有多种解决方案,请输出任何解决方案。 ## 输入格式 第一行包含一个正整数n(1≤n≤2000),表示方板的大小。 接下来的n行是长度n的字符串,由1和0组成,表示从顶行开始的正方形板的初始状态。如果字符串中的字符为1,则表示灯已打开,否则为关闭。 接下来的n行是长度n的字符串,由1和0组成,表示从鲍勃给爱丽丝的方板的所需状态。 最后一行是一个长度为n的字符串,由1和0组成,以从左到右的顺序表示魔棒上面灯光的状态。 ## 输出格式 把爱丽丝的指令转换成鲍勃给她的模式。输出的第一行包含一个整数m(0≤m≤1e5),表示爱丽丝需要应用魔法棒的次数。 接下来的m行是“col x”或“row x”的形式,其中x是行或列的序号(从零开始),这意味着魔棒应该应用于row x或column x。如果没有解决方案,只输出-1。如果有多个解决方案,请输出任何正确的解决方案。

题目描述

For her birthday Alice received an interesting gift from her friends – The Light Square. The Light Square game is played on an $ N \times N $ lightbulbs square board with a magical lightbulb bar of size $ N \times 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 \leq N \leq 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 \leq M \leq 10^5 $ ) 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.

Input

题意翻译

## 题目描述 爱丽丝在她的生日那天收到了朋友们送她的一件有趣的礼物——光明方板。光明方板游戏是在一个n×n灯泡方板上玩的,方板上有一个n×1大小的具有魔法属性的魔法灯棒。游戏开始时,方块板和魔法棒上的一些灯都会亮起。这个游戏的目标是在不旋转方板的情况下,使用魔法棒将起始方板图案转换成其他图案。神奇魔法棒的工作原理如下: 它可以放在任何行或列上 魔法棒的方向必须从左到右或从上到下,这样才能保持其魔法特性 整根魔法棒都要放在方板上 魔法棒的灯光永不改变 如果魔法棒上的灯和方板上的灯的状态是一样的,它会把方板上的灯关掉,否则它会把灯打开 魔法棒可以无限次使用 爱丽丝很难把她的方板变成鲍勃给她的式样。你能帮她把方板上的灯改变成想要的样子或者让她知道这是不可能的么?如果有多种解决方案,请输出任何解决方案。 ## 输入格式 第一行包含一个正整数n(1≤n≤2000),表示方板的大小。 接下来的n行是长度n的字符串,由1和0组成,表示从顶行开始的正方形板的初始状态。如果字符串中的字符为1,则表示灯已打开,否则为关闭。 接下来的n行是长度n的字符串,由1和0组成,表示从鲍勃给爱丽丝的方板的所需状态。 最后一行是一个长度为n的字符串,由1和0组成,以从左到右的顺序表示魔棒上面灯光的状态。 ## 输出格式 把爱丽丝的指令转换成鲍勃给她的模式。输出的第一行包含一个整数m(0≤m≤1e5),表示爱丽丝需要应用魔法棒的次数。 接下来的m行是“col x”或“row x”的形式,其中x是行或列的序号(从零开始),这意味着魔棒应该应用于row x或column x。如果没有解决方案,只输出-1。如果有多个解决方案,请输出任何正确的解决方案。

加入题单

算法标签: