CF1718E.Impressionism
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Burenka has two pictures a and b , which are tables of the same size n×m . Each cell of each painting has a color — a number from 0 to 2⋅105 , and there are no repeating colors in any row or column of each of the two paintings, except color 0 .
Burenka wants to get a picture b from the picture a . To achieve her goal, Burenka can perform one of 2 operations: swap any two rows of a 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 1 to n from top to bottom, the columns are numbered from 1 to m from left to right.
输入格式
The first line contains two integers n and m ( 1≤n⋅m≤2⋅105 ) — the sizes of the table.
The i -th of the next n lines contains m integers ai,1,ai,2,…,ai,m ( 0≤ai,j≤2⋅105 ) — the colors of the i -th row of picture a . It is guaranteed that there are no identical colors in the same row or column, except color 0 .
The i -th of the following n lines contains m integers bi,1,bi,2,…,bi,m ( 0≤bi,j≤2⋅105 ) — the colors of the i -th row of picture b . It is guaranteed that there are no identical colors in the same row or column, except color 0 .
输出格式
In the first line print the number −1 if it is impossible to achieve what Burenka wants, otherwise print the number of actions in your solution k ( 0≤k≤2⋅105 ). It can be proved that if a solution exists, then there exists a solution where k≤2⋅105 .
In the next k lines print the operations. First print the type of the operation ( 1 — swap rows, 2 — 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
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