CF1218I.The Light Square

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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×NN \times N lightbulbs square board with a magical lightbulb bar of size N×1N \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 Light Square)。
“光之方阵”游戏在一个 N×NN \times N 的灯泡方阵棋盘上进行,并配有一根尺寸为 N×1N \times 1 的魔法灯泡条,该灯泡条具有神奇的性质。游戏开始时,方阵棋盘上以及魔法灯泡条上均已有部分灯处于点亮状态。游戏目标是:不旋转方阵棋盘,仅借助该魔法灯泡条,将初始的灯泡方阵图案转变为指定的目标图案。魔法灯泡条的工作方式如下:

  • 它可以放置在任意一行或任意一列上;
  • 为保持其魔法性质,该魔法灯泡条的方向必须为从左到右(水平放置)或从上到下(垂直放置);
  • 整根灯泡条必须完全置于棋盘之上(即不可悬出边界);
  • 魔法灯泡条自身的灯状态永不改变;
  • 当魔法灯泡条上的某个灯与其所覆盖的棋盘位置上的灯状态相同时,则将该棋盘位置上的灯关闭;否则(即状态不同),则将该棋盘位置上的灯开启;
  • 魔法灯泡条可被使用无限次。

爱丽丝很难将她的方阵棋盘转变为鲍勃给她的目标图案。你能帮她完成这一转换,或告诉她这是不可能的吗?若存在多种解法,请输出任意一种即可。

输入格式

The first line contains one positive integer number N (1≤N≤2000)N\ (1 \leq N \leq 2000) representing the size of the square board.

The next NN lines are strings of length NN 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 NN lines are strings of length NN 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 NN consisting of 1's and 0's representing the pattern of the magical bar in a left to right order.

第一行包含一个正整数 N (1≤N≤2000)N\ (1 \leq N \leq 2000),表示方格棋盘的尺寸。

接下来的 NN 行,每行是一个长度为 NN 的字符串,由字符 1 和 0 组成,表示方格棋盘的初始状态(从最上方一行开始)。若字符串中某位置的字符为 1,则表示该位置的灯处于开启状态;否则为关闭状态。

再接下来的 NN 行,每行是一个长度为 NN 的字符串,由字符 1 和 0 组成,表示 Bob 给 Alice 指定的目标状态(从最上方一行开始)。

最后一行是一个长度为 NN 的字符串,由字符 1 和 0 组成,表示魔法棒的模式(从左到右的顺序)。

输出格式

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≤105M\ (0 \leq M \leq 10^5) representing the number of times Alice will need to apply the magical bar.

The next MM lines are of the form "col XX" or "row XX", where XX is 00-based index of the matrix, meaning the magical bar should be applied to either row XX or column XX. If there is no solution, print only -1. In case of multiple solutions print any correct one.

将指令转换为爱丽丝的操作,使其能将方格棋盘变换为鲍勃给她的目标图案。输出的第一行包含一个整数 M (0≤M≤105)M\ (0 \leq M \leq 10^5),表示爱丽丝需要使用魔法棒的次数。

接下来的 MM 行每行格式为 “col XX” 或 “row XX”,其中 XX 是矩阵的 0-基索引,表示魔法棒应作用于第 XX 行或第 XX 列。若无解,则仅输出 -1。若存在多个解,输出任意一个正确解即可。

输入输出样例

  • 输入#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.

示例 1:无法将方格棋盘从一种格式变换为另一种格式。

示例 2:魔法条可应用于第一行或第一列。

输入解题思路,AI测评打分。不知道怎么写?

首页