感觉能过的代码只有13pts
查看原帖
感觉能过的代码只有13pts
201738
陳宇翔楼主2022/11/26 20:55

rt

//I love zhang Shuhao awa
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int n,m,a[1010][1010];
long long fc[1010][1010],ff[1010][1010];
long long ansf,ansc,p=998244353;

void work_c(){
	memset(fc,0,sizeof(fc)); 
	ansc=0;
	for (int i=1;i<=n;++i){
		fc[i][m+1]=0;
		for (int j=m;j>=1;--j){
			if (!a[i][j]){
				fc[i][j]=fc[i][j+1]+1;
			}
			else{
				fc[i][j]=0;
			}
		}
	}	
	for (int j=1;j<=m;++j){
		long long sum=0;
		int last_0=0;
		if (a[2][j]){
			last_0=2;
		}
		else {
			if (a[1][j]){
				last_0=1;
			}
		}
		for (int i=3;i<=n;++i){
			if (a[i][j]){
				last_0=i;
				sum=0;
			}
			if (i-2>last_0){
				sum+=fc[i-2][j]-1;
			}
			ansc=ansc+sum*fc[i][j]-sum;
			if (ansc>p) {
				ansc%=p;
			}
		} 
	}
}

void work_f(){
	ansf=0;
	memset(ff,0,sizeof(ff));
	for (int j=1;j<=m;++j){
		ff[n+1][j]=0;
		for (int i=n;i>=1;--i){
			if (!a[i][j]){
				ff[i][j]=ff[i+1][j]+1;
			}
			else{
				ff[i][j]=0;
			}
		}
	}
	for (int j=1;j<=m;++j){
		long long sum=0;
		int last_0=0;
		if (a[2][j]){
			last_0=2;
		}
		for (int i=3;i<=n;++i){
			if (a[i][j]){
				last_0=i;
				sum=0;
			}
			if (i-2>last_0){
				sum+=fc[i-2][j]-1;
			}
			ansf=ansf+sum*(fc[i][j]-1)*(ff[i][j]-1);
			if (ansf>p) {
				ansf%=p;
			}
		} 
	}
}

int main(){
//	freopen("plant.in","r",stdin);
//	freopen("plant.out","w",stdout);
	long long C,F;
	int T,id;
	scanf("%d%d",&T,&id);
	while (T--){
		scanf("%d%d%lld%lld",&n,&m,&C,&F);
		memset(a,0,sizeof(a));
		for (int i=1;i<=n;++i){
			string s;
			cin>>s;
			for (int j=1;j<=m;++j){
				a[i][j]=s[j-1]-'0';
			}
		}
		work_c();
		work_f();
		ansc=(ansc*C)%p;
		ansf=(ansf*F)%p;
		printf("%lld %lld\n",ansc,ansf);
	}
//	fclose(stdin);fclose(stdout);
	return 0;
}
2022/11/26 20:55
加载中...