Problem 992
Determine Whether Matrix Can Be Obtained By Rotation
Easy · 10 pts · Matrix
Problem
Given two N × N binary matrices MAT and TARGET, decide whether MAT can be turned into TARGET by rotating it clockwise by 90 degrees some number of times (zero, one, two or three times). Rotating clockwise moves the element at row i, column j to row j, column N - 1 - i. Rotate MAT up to three times and compare it with TARGET after each step.
Input
The first line contains N. The next N lines are the rows of MAT, and the N lines after them are the rows of TARGET, each with N values 0 or 1.
Output
Print YES if some rotation of MAT equals TARGET, otherwise NO.
Constraints
1 <= N <= 10
Example input
2 0 1 1 0 1 0 0 1
Example output
YES
Explanation
Rotating 0 1 / 1 0 by 90 degrees clockwise gives 1 0 / 0 1, which equals TARGET, so the answer is YES.