Palindromic Paths
调试惨了
调试成了傻子
TELEPORT
思路参考于此
坚持用(1,1)作为坐标起始点,然后自己按照思路写了一次
真的调吐了
#include<cassert>
#include<string>
#include<cmath>
#include<cstring>
#include<stack>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<cstdlib>
#pragma warning(disable:4996)
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f
#define itn int
#define ll long long
#define mes(a,k) memset(a,k,sizeof(a))
//#define max(a,b) a>b?a:b
//#define min(a,b) a<b?a:b
//#define pb(a) push_back(a)
#define eps 1e-9
#define PI acos(-1)
using namespace std;
const int N = 2e5 + 5;
int matr[32][32];
void io(){ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);}
int main(){
io();
int T;
cin>>T;
while(T--){
mes(matr,0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>matr[i][j];
}
}
int len=n+m-1;//奇数,中间不管,偶数,刚好管住
int res=0;
for(int i=1;i<=len/2;i++){
int arr[2][2]={0};
int ii=i,jj=1;
if(ii>n){
jj+=ii-n;
ii=n;
}
//cout<<"i22: "<<ii<<" j22: "<<jj<<endl;
while(jj<=m&&ii>=1){
//cout<<"i: "<<ii<<" j: "<<jj<<endl;
arr[0][matr[ii][jj]]++;
jj++;
ii--;
}
jj=m-i+1,ii=n;
if(jj<1){
ii+=jj-1;
jj=1;
}
while(jj<=m&&ii>=1){
//cout<<"i: "<<ii<<" j: "<<jj<<endl;
arr[1][matr[ii][jj]]++;
jj++,ii--;
}
res+=min(arr[1][0]+arr[0][0],arr[1][1]+arr[0][1]);
}
cout<<res<<endl;
}
return 0;
}