QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404631#8552. SticksOvO_ZuoTL 1ms5860kbC++141.7kb2024-05-04 10:51:512024-05-04 10:51:53

Judging History

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

  • [2024-05-04 10:51:53]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5860kb
  • [2024-05-04 10:51:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3005,mo=998244353;
int n;
char s[N][N];
int dp[N][N];
int add(int x,int y) {x+=y;return x>=mo?x-mo:x;}
int suf[N];
int mn[N],mx[N];
int main()
{
	scanf("%d",&n);
	int i,j,k;
	for(i=1;i<=n;i++) scanf("%s",s[i]+1);
	fill(mx,mx+1+n,0);
	fill(mn,mn+1+n,n+1);
	for(i=n;i>=1;--i) 
		for(j=1;j<=n;j++) 
			if(s[i][j]=='0') mn[j]=i;
	
	for(i=0;i<=n;i++) dp[0][i]=1;
	int lst,mn0;
	for(i=1;i<=n;i++) {
		for(j=1;j<=n;j++)
			if(s[i][j]=='1') mx[j]=i;
		for(j=1;j<=n;j++) {
			suf[j+1]=1;
			for(k=j;k>1;--k) 
				suf[k]=(ll)suf[k+1]*max(0,min(i+1,mn[k])-mx[k])%mo;
			for(mn0=j+1,k=j;k>=1;k--) 
				if(s[i][k]=='0') mn0=k;
			for(lst=0,k=1;k<=j;k++) {
				if(mn[k]>i) {
					// cout<<i<<" "<<j<<" "<<k<<" "<<mn0<<" "<<lst<<" "<<dp[i-1][k-1]<<" "<<suf[k+1]<<endl;
					dp[i][j]=add(dp[i][j],
						(ll)dp[i-1][k-1]*suf[k+1]%mo*
							max(0,min(k-1,mn0)-lst)%mo);
				}
				if(s[i][k]=='1') lst=k;
			}
			// cout<<"lst:"<<i<<" "<<j<<" "<<mn0<<" "<<lst<<" "<<dp[i-1][j]<<endl;
			dp[i][j]=add(dp[i][j],(ll)max(0,(mn0-lst))*dp[i-1][j]%mo);
			// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
	}
	printf("%d\n",dp[n][n]);
	return 0;
}
/*
问:有多少个 n*n 的 01 矩形 A 满足能找到一组 x[1~n],y[1~n]
其中一些位置的 01 已经给定
满足 不存在 x[i]>=j&&y[j]>=i 且 A[i][j] = [(x[i]>=j)||(y[j]>=i)]
考虑判断一个 A 矩阵是否合法
每次尝试删掉最后一行
显然令最后一行的 x[n] 尽量大,找到最小的 p>x[n]+1 满足 A[n][p] = 1
显然第 p 列的 y[p] 应 = n, p~m 列可以自由选择
问题变成 n-1 * p
转移时只枚举 p 即可
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5860kb

input:

2
??
??

output:

14

result:

ok 1 number(s): "14"

Test #2:

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

input:

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

output:

3144

result:

ok 1 number(s): "3144"

Test #3:

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

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: