RithwikG's picture
initial commit
7a8878c
raw
history blame contribute delete
958 Bytes
You have been given a matrix a of size n by m, containing a permutation of integers from 1 to n⋅m.A permutation of n integers is an array containing all numbers from 1 to n exactly once. For example, the arrays [1], [2,1,3], [5,4,3,2,1] are permutations, while the arrays [1,1], [100], [1,2,4,5] are not.A matrix contains a permutation if, when all its elements are written out, the resulting array is a permutation. Matrices [[1,2],[3,4]], [[1]], [[1,5,3],[2,6,4]] contain permutations, while matrices [[2]], [[1,1],[2,2]], [[1,2],[100,200]] do not.You can perform one of the following two actions in one operation: choose columns c and d (1≤c,d≤m, c≠d) and swap these columns; choose rows c and d (1≤c,d≤n, c≠d) and swap these rows. You can perform any number of operations.You are given the original matrix a and the matrix b. Your task is to determine whether it is possible to transform matrix a into matrix b using the given operations.