fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4.  
  5. ios::sync_with_stdio(false);
  6. cin.tie(NULL);
  7.  
  8. int t;
  9. cin>>t;
  10.  
  11. while(t--){
  12. int n;
  13. cin>>n;
  14. int arr[n][n];
  15. for(int i=0; i<n; ++i){
  16. for(int j=0; j<n; ++j){
  17. cin>>arr[i][j];
  18. }
  19. }
  20.  
  21. int exit=1;
  22.  
  23. if(n%2!=0){
  24. for(int j=0; j<(n/2)-1; ++j){
  25. if(arr[n/2][j]!=arr[n/2][(n/2)+j]){
  26. exit=0;
  27. break;
  28. }
  29. }
  30. }
  31. for(int i=0; i<n/2; ++i){
  32. for(int j=0; j<n; ++j){
  33. if(arr[i][j]!=arr[(n/2)+i][j]){
  34. exit=0;
  35. break;
  36. }
  37. }
  38. if(exit){
  39. break;
  40. }
  41. }
  42. cout<<(exit==1?"YES":"NO")<<'\n';
  43.  
  44.  
  45. }
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0.01s 5280KB
stdin
5
2
11
11
4
0101
0110
0110
0101
4
1001
0000
0000
1001
5
01110
01010
10001
01010
01110
5
00100
01010
10001
01010
01110
stdout
NO
NO
NO
NO
NO