#K78622. Matrix Transformation Challenge
Matrix Transformation Challenge
Matrix Transformation Challenge
You are given an N × N square matrix and a target matrix of the same size. Your task is to determine whether the target matrix can be obtained from the original matrix by performing a sequence of operations. The allowed operations are:
- Transpose: Swap rows with columns.
- Reverse each row: Reverse the elements of every row.
You may apply these operations in any order and any number of times (including zero), but only the following combinations are considered:
- The original matrix.
- The transposed matrix.
- The matrix with each row reversed.
- The matrix obtained by first reversing each row and then transposing.
- The matrix obtained by first transposing and then reversing each row.
Formally, given a starting matrix \( A \) and a target matrix \( B \), determine if \( B \) equals any one of the matrices obtained by the operations above.
inputFormat
The input is read from standard input (stdin) and has the following format:
T N a[1][1] a[1][2] ... a[1][N] ... a[N][1] a[N][2] ... a[N][N] b[1][1] b[1][2] ... b[1][N] ... b[N][1] b[N][2] ... b[N][N] ... (this pattern repeats for each of the T test cases)
Where:
- T is the number of test cases.
- For each test case, the first line contains an integer N (1 ≤ N ≤ 100), the size of the matrix.
- The next N lines each contain N integers, representing the starting matrix.
- The following N lines each contain N integers, representing the target matrix.
outputFormat
For each test case, output a single line containing YES
if the target matrix can be obtained by performing the operations described above on the starting matrix; otherwise, output NO
.
Output is written to standard output (stdout).
## sample4
2
1 2
3 4
3 1
4 2
3
1 2 3
4 5 6
7 8 9
3 6 9
2 5 8
1 4 7
3
1 2 3
4 5 6
7 8 9
9 8 7
6 5 4
3 2 1
2
1 2
3 4
4 3
2 1
YES
YES
NO
NO
</p>