QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717364#8552. Sticksborn_to_sunTL 3ms81468kbC++141.3kb2024-11-06 17:43:512024-11-06 17:43:51

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 17:43:51]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:81468kb
  • [2024-11-06 17:43:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int mod=998244353;
const int N=3e3+5;
int qpow(int a,int x){
	int sum=1;
	while(x){
		if(x&1) sum=sum*a%mod;
		a=a*a%mod;
		x>>=1;
	}return sum;
}
int n;
char a[N][N];
int S0[N][N],S[N][N];
int g[N][N],h[N][N];
int f[N][N];
int pw[N*N];
void init(){
	pw[0]=1;
	for(int i=1;i<=n*n;i++) pw[i]=pw[i-1]*2%mod;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) S0[i][j]=S0[i][j-1]+S0[i-1][j]-S0[i-1][j-1]+(a[i][j]=='0'),S[i][j]=S[i][j-1]+(a[i][j]=='?');
	}
	for(int i=1;i<=n;i++){
		g[i][0]=1;
		for(int j=1;j<=n;j++){
			g[i][j]=g[i][j-1]*(a[i][j]!='1')+(S0[i][j]-S0[i-1][j]==0);
		}
	}
	for(int j=1;j<=n;j++){
		h[0][j]=1;
		for(int i=1;i<=n;i++) h[i][j]=h[i-1][j]*(a[i][j]!='1')+(S0[i][j]-S0[i][j-1]==0);
	}
}
int dfs(int x,int y){
	if(x<=0||y<=0) return 1;
	if(~f[x][y]) return f[x][y];
	int res=0;
	int now=1;
	for(int i=x;i>=2;i--){
		if(S0[i][y]-S0[i-1][y]==0&&a[i-1][y]!='1'){
			res+=dfs(i-1,y-1)*now%mod*h[i-2][y]%mod;
		}
		now*=g[i][y];
	}
	res+=dfs(x,y-1)*h[x][y]%mod;
	// cerr<<x<<" "<<y<<" "<<res<<' '<<now<<' '<<g[1][y]<<'\n';
	return f[x][y]=res%mod;
}
signed main(){
	memset(f,-1,sizeof(f));
	cin>>n;
	for(int i=1;i<=n;i++) cin>>(a[i]+1);
	init();
	cout<<dfs(n,n);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 79480kb

input:

2
??
??

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 3ms
memory: 81428kb

input:

5
??1??
?1??0
??0??
???1?
??1??

output:

3144

result:

ok 1 number(s): "3144"

Test #3:

score: 0
Accepted
time: 0ms
memory: 81468kb

input:

10
0000000000
??????????
??????????
??????????
??????????
??????????
??????????
??????????
??????????
??????????

output:

361458985

result:

ok 1 number(s): "361458985"

Test #4:

score: -100
Time Limit Exceeded

input:

3000
??????????????????????????????????????????????????????????0?????????????????????0??????????????????????????????????????????????????????????????????????????????????????0???????????????????????????????????????????0???????????????????????????????????????????????????????????????????????????????????...

output:


result: