How to solve this problem - https://codeforces.com/contest/1136/problem/C

I have looked after some codes, most them had this snippet x[i + j] = a[i][j] and y[i + j] = b[i][j];

But I couldn’t understand the logic behind it, anyone explain me.

You can observe that when you transpose a submatrix ,the effect will always upon the diagonal (all diagonal of that sub matrix and a part of diagonal of main matrix), Now here comes the cases of duplicate elements, now we can’t handle them (diagonal elements) using map so we will just sort them to compare with required matrix.A little bit observation

1 Like

The logic behind it is to store the diagonal elements of the matrix, sort each of them and check for equality.