1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) int rd(){ int IO,s=0; while(!isdigit(IO=getchar())); do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return s; }
int a[4][4]; int Check(){ rep(i,1,3) rep(j,1,3) if(a[i][j]) { int fl=1; rep(k,1,3) if(j!=k && !a[i][k]) fl=0; rep(k,1,3) if(k!=i && !a[k][j]) fl=0; if(!fl) continue; int x=a[i][j],ans=0; a[i][j]=0; rep(i,1,3) rep(j,1,3) if(a[i][j]) ans^=a[i][j]-1; ans^=x,a[i][j]=x; return ans; } return '?'; }
int main(){ rep(kase,1,rd()) { rep(i,1,3) rep(j,1,3) a[i][j]=rd(); int ans=0; rep(i,1,3) rep(j,1,3) { int t=a[i][j]; a[i][j]=0; int fl=0; rep(x,1,3) rep(y,1,3) { if(x==i || y==j) continue; int t=a[x][y]; a[x][y]=0; if(!Check()) fl=1; a[x][y]=t; } if(!fl) ans++; a[i][j]=t; } printf("%d\n",ans); } }
|