CF1718E.Impressionism

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Burenka has two pictures aa and bb, which are tables of the same size n×mn \times m. Each cell of each painting has a color — a number from 00 to 2⋅1052 \cdot 10^5, and there are no repeating colors in any row or column of each of the two paintings, except color 00.

Burenka wants to get a picture bb from the picture aa. To achieve her goal, Burenka can perform one of 22 operations: swap any two rows of aa or any two of its columns. Tell Burenka if she can fulfill what she wants, and if so, tell her the sequence of actions.

The rows are numbered from 11 to nn from top to bottom, the columns are numbered from 11 to mm from left to right.

布尔恩卡有两幅画 aa 和 bb,它们均为大小为 n×mn \times m 的表格。每幅画的每个格子均有一种颜色——一个从 00 到 2⋅1052 \cdot 10^5 的整数;且在每幅画的任意一行或一列中,除颜色 00 外,其余颜色均不重复。

布尔恩卡希望将画 aa 变为画 bb。为实现该目标,她可执行以下两种操作之一:交换 aa 的任意两行,或交换 aa 的任意两列。请告诉布尔恩卡她能否达成目标;若可以,请给出所需的操作序列。

行编号从上到下依次为 11 至 nn,列编号从左到右依次为 11 至 mm。

输入格式

The first line contains two integers nn and mm (1≤n⋅m≤2⋅1051 \leq n \cdot m \leq 2 \cdot 10^5) — the sizes of the table.

The ii-th of the next nn lines contains mm integers ai,1,ai,2,…,ai,ma_{i, 1}, a_{i, 2}, \ldots, a_{i, m} (0≤ai,j≤2⋅1050 \leq a_{i,j} \leq 2 \cdot 10^5) — the colors of the ii-th row of picture aa. It is guaranteed that there are no identical colors in the same row or column, except color 00.

The ii-th of the following nn lines contains mm integers bi,1,bi,2,…,bi,mb_{i, 1}, b_{i, 2}, \ldots, b_{i, m} (0≤bi,j≤2⋅1050 \leq b_{i,j} \leq 2 \cdot 10^5) — the colors of the ii-th row of picture bb. It is guaranteed that there are no identical colors in the same row or column, except color 00.

第一行包含两个整数 nn 和 mm(1≤n⋅m≤2⋅1051 \leq n \cdot m \leq 2 \cdot 10^5)—— 表格的尺寸。

接下来的 nn 行中,第 ii 行包含 mm 个整数 ai,1,ai,2,…,ai,ma_{i, 1}, a_{i, 2}, \ldots, a_{i, m}(0≤ai,j≤2⋅1050 \leq a_{i,j} \leq 2 \cdot 10^5)—— 图片 aa 第 ii 行的颜色。保证在同一行或同一列中,除颜色 00 外不存在相同的颜色。

再接下来的 nn 行中,第 ii 行包含 mm 个整数 bi,1,bi,2,…,bi,mb_{i, 1}, b_{i, 2}, \ldots, b_{i, m}(0≤bi,j≤2⋅1050 \leq b_{i,j} \leq 2 \cdot 10^5)—— 图片 bb 第 ii 行的颜色。保证在同一行或同一列中,除颜色 00 外不存在相同的颜色。

输出格式

In the first line print the number −1-1 if it is impossible to achieve what Burenka wants, otherwise print the number of actions in your solution kk (0≤k≤2⋅1050 \le k \le 2 \cdot 10^5). It can be proved that if a solution exists, then there exists a solution where k≤2⋅105k \le 2 \cdot 10^5.

In the next kk lines print the operations. First print the type of the operation (11 — swap rows, 22 — columns), and then print the two indices of rows or columns to which the operation is applied.

Note that you don't have to minimize the number of operations.

第一行输出数字 −1-1,表示无法实现布尔恩卡的目标;否则输出你所构造的解中操作次数 kk(0≤k≤2⋅1050 \le k \le 2 \cdot 10^5)。可以证明:若解存在,则必存在一个满足 k≤2⋅105k \le 2 \cdot 10^5 的解。

接下来 kk 行,每行描述一次操作:首先输出操作类型(11 表示交换两行,22 表示交换两列),然后输出被操作的两行或两列的下标。

注意:你无需最小化操作次数。

输入输出样例

  • 输入#1

    3 3
    1 0 2
    0 0 0
    2 0 1
    2 0 1
    0 0 0
    1 0 2

    输出#1

    1
    1 1 3
  • 输入#2

    4 4
    0 0 1 2
    3 0 0 0
    0 1 0 0
    1 0 0 0
    2 0 0 1
    0 3 0 0
    0 1 0 0
    0 0 1 0

    输出#2

    4
    1 3 4
    2 3 4
    2 2 3
    2 1 2
  • 输入#3

    3 3
    1 2 0
    0 0 0
    0 0 0
    1 0 0
    2 0 0
    0 0 0

    输出#3

    -1

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

首页