cf1027E Inverse Coloring dp


Description
You are given a square board, consisting of n n n rows and n n n columns. Each tile in it should be colored either white or black.
Let’s call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well.
Let’s call some coloring suitable if it is beautiful and there is no rectangle of the single color, consisting of at least k k k tiles.
Your task is to count the number of suitable colorings of the board of the given size.
Since the answer can be very large, print it modulo 998244353 998244353 998244353 .
Solution
まず、1行と1列01からなる数列x[]y[]が存在し、a[i,j]=x[i]^y[i]とすれば、条件1と2を満たす矩形が得られる.3番目の条件についてdpを考慮し、f[i,j,k]を満足長さがちょうどiであり、最大連続がjであり、末尾連続がkである01配列の数を表すとし、統計して乗せればよい
Code
#include 
#include 
#include 
#define rep(i,st,ed) for (register int i=st,_=ed;i<=_;++i)
#define fill(x,t) memset(x,t,sizeof(x))

typedef long long LL;
const int MOD=998244353;
const int N=505;

LL f[2][N][N],g[N][N];

void upd(LL &x,LL v) {
	x=x+v; x%=MOD;
}

int main(void) {
	freopen("data.in","r",stdin);
	int n,m; scanf("%d%d",&n,&m);
	f[0][0][0]=1;
	rep(i,0,n) {
		int x=i&1;
		fill(f[!x],0);
		rep(j,0,i) {
			rep(k,0,std:: min(i,j)) {
				upd(f[!x][std:: max(j,k+1)][k+1],f[x][j][k]);
				upd(f[!x][std:: max(j,1)][1],f[x][j][k]);
				upd(g[i][j],f[x][j][k]);
			}
		}
	}
	LL ans=0;
	rep(i,1,n) rep(j,1,n) {
		if (i*j<m) upd(ans,1LL*g[n][i]*g[n][j]%MOD);
		else break;
	}
	ans=499122177LL*ans%MOD;
	printf("%lld
"
, ans); return 0; }