[Solution] Angled Flip CodeChef Solution
Problem
You are given two integer matrices and . You are allowed to perform the following operation on as many times as you like (possibly, zero):
- Pick any square submatrix of and flip it about either its main diagonal or its antidiagonal.
For example, suppose you choose the submatrix .
It can be converted into either by flipping about the main diagonal, or by flipping about the antidiagonal.
Is it possible to convert to by performing this operation several (possibly, zero) times?
Note: For the purposes of this problem, a submatrix of a matrix is the intersection of a contiguous segment of rows
with a contiguous segment of columns.
For example, if then , , and are submatrices of , while is not.
A square submatrix is a submatrix with the same number of rows and columns.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two space-separated integers and — the number of rows and columns of the matrices, respectively.
- The next lines describe the matrix . The -th of these lines contains space-separated integers ― the values .
- The next lines describe the matrix . The -th of these lines contains space-separated integers ― the values .
Output Format
For each test case, print YES
if its possible to convert to , else print NO
.
Each character of the output may be printed in either uppercase or lowercase. For example, the strings YES
, yes
, yeS
, YeS
will all be treated as identical.
Explanation:
Test case : can be converted to as follows:
No comments:
Post a Comment