fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. typedef long long ll;
  4. using namespace std;
  5.  
  6. void solve() {
  7. int n,k;
  8. cin>>n>>k;
  9. vector<vector<int>> v(n,vector<int>(n,0));
  10. for(int i=0;i<n;i++){
  11. for(int j=0;j<n;j++){
  12. cin>>v[i][j];
  13. }
  14. }
  15. int ans=0;
  16. for(int i=0;i<n/2;i++){
  17. for(int j=0;j<n;j++){
  18. if(v[i][j]!=v[n-i-1][n-j-1]){
  19. ans++;
  20. }
  21. }
  22. }
  23. if(n%2!=0){
  24. for(int j=0;j<n/2;j++){
  25. if(v[n/2][j]!=v[n/2][n-j-1]){
  26. ans++;
  27. }
  28. }
  29. }
  30. // cout<<ans<<endl;
  31. if(ans>k){
  32. cout<<"NO"<<endl;
  33. }
  34. else{
  35. int left=k-ans;
  36. if(left%2==0){
  37. cout<<"YES"<<endl;
  38. }
  39. else {
  40. if(n%2!=0){
  41. cout<<"YES"<<endl;
  42. }
  43. else{
  44. cout<<"NO"<<endl;
  45. }
  46.  
  47. }
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. }
  56.  
  57. signed main() {
  58. int t;
  59. cin >> t;
  60. while (t--) {
  61. solve();
  62. }
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0.01s 5284KB
stdin
3
4 0
1 1 1 1
0 0 0 1
1 0 1 0
1 1 1 1
4 3
1 0 1 1
1 0 0 0
0 1 0 1
1 1 0 1
5 4
0 0 0 0 0
0 1 1 1 1
0 1 0 0 0
1 1 1 1 1
0 0 0 0 0
stdout
NO
YES
YES