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
| #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define Tp template<typename Ty> #define Ts template<typename Ty,typename... Ar> #define W while #define I inline #define RI register int #define LL long long #define Cn const #define CI Cn int& using namespace std; namespace Debug{ Tp I void _debug(Cn char* f,Ty t){cerr<<f<<'='<<t<<endl;} Ts I void _debug(Cn char* f,Ty x,Ar... y){W(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);} Tp ostream& operator<<(ostream& os,Cn vector<Ty>& V){os<<"[";for(Cn auto& vv:V) os<<vv<<",";os<<"]";return os;} #define gdb(...) _debug(#__VA_ARGS__,__VA_ARGS__) }using namespace Debug; namespace FastIO{ #define FS 100000 #define tc() (FA==FB&&(FB=(FA=FI)+fread(FI,1,FS,stdin),FA==FB)?EOF:*FA++) #define pc(c) (FC==FE&&(clear(),0),*FC++=c) int OT;char oc,FI[FS],FO[FS],OS[FS],*FA=FI,*FB=FI,*FC=FO,*FE=FO+FS; I void clear() {fwrite(FO,1,FC-FO,stdout),FC=FO;} Tp I void read(Ty& x) {x=0;RI f=1;W(!isdigit(oc=tc())) f=oc^'-'?1:-1;W(x=(x<<3)+(x<<1)+(oc&15),isdigit(oc=tc()));x*=f;} Ts I void read(Ty& x,Ar&... y) {read(x),read(y...);} Tp I void write(Ty x) {x<0&&(pc('-'),x=-x);W(OS[++OT]=x%10+48,x/=10);W(OT) pc(OS[OT--]);} Tp I void writeln(Ty x) {x<0&&(pc('-'),x=-x);W(OS[++OT]=x%10+48,x/=10);W(OT) pc(OS[OT--]);pc('\n');} }using namespace FastIO; Cn int N=75,M=8,P=998244353; int T,n,m,a[N][M],Ans,dp[2][(1<<7)+5][(1<<7)+5],C; I void go(int& x,CI y){(x+=y)>=P&&(x-=P,0);} int main(){ freopen("grid.in","r",stdin),freopen("grid.out","w",stdout); RI i,j,k,s1,s2,t1,t2,o1,o2,p,S=0;read(T);W(T--){ for(read(n,m),C=(1<<m+1),i=1;i<=n;i++) for(j=1;j<=m;j++) read(a[i][j]); for(memset(dp,0,sizeof(dp)),dp[S=0][0][0]=1,i=1;i<=n;i++) for(j=1;j<=m;j++) for(S^=1,memset(dp[S],0,sizeof(dp[S])),k=(~a[i][j]?a[i][j]:0);k<=(~a[i][j]?a[i][j]:4);k++) for(s1=0;s1<C;s1++) if(p=k-(s1&1)-(s1>>j&1),0<=p&&p<=2) for(t1=t2=s1&(C-2)&(C-(1<<j)-1),!p?t2=C:p&1?t1^=1,t2^=1<<j:(t1^=1+(1<<j),t2=C),s2=0;s2<C;s2++) if(j>1(!(s1&1)&&!(s2&1))) if(p=k-(s2&1)-(s2>>j&1),0<=p&&p<=2) o1=o2=s2&(C-2)&(C-(1<<j)-1),!p?o2=C:p&1?o1^=1,o2^=1<<j:(o1^=1+(1<<j),o2=C),t1<C&&o1<C&&(go(dp[S][t1][o1],dp[S^1][s1][s2]),0),t1<C&&o2<C&&(go(dp[S][t1][o2],dp[S^1][s1][s2]),0),t2<C&&o1<C&&(go(dp[S][t2][o1],dp[S^1][s1][s2]),0),t2<C&&o2<C&&(go(dp[S][t2][o2],dp[S^1][s1][s2]),0); writeln(dp[S][0][0]); }return clear(),0; }
|