luogu的数据好水
查看原帖
luogu的数据好水
750240
Hellsing_Alucard楼主2022/11/27 10:46

O(n^5)70pts

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int a[1250][1250],n,m,c,f;
long long vc,vf;
inline bool check1(int x1,int x2,int y0){
	for(int i=x1;i<=x2;i++){if(a[i][y0]) return 0;}
	return 1;
}
inline bool check2(int x1,int y0,int y1){
	for(int i=y0;i<=y1;i++){if(a[x1][i]) return 0;}
	return 1;
}
inline bool check3(int x2,int y0,int y2){
	for(int i=y0;i<=y2;i++){if(a[x2][i]) return 0;}
	return 1;
}
int main(){
	//freopen("plant.in","r",stdin);
	//freopen("plant.out","w",stdout);
	int t=read(),id=read();
	while(t--){
		memset(a,0,sizeof a);vc=0;vf=0;
		n=read();m=read();c=read();f=read();
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				scanf("%1d",&a[i][j]);
			}
		}
		if(c==0&&f==0){
			printf("0 0\n");
			continue;
		}
		int j;
		for(int x1=1;x1<n-1;x1++){
			for(int x2=x1+2;x2<=n;x2++){
				for(int y0=1;y0<m;y0++){
					if(!check1(x1,x2,y0)) continue;
					for(int y1=y0+1;y1<=m;y1++){
						if(!check2(x1,y0,y1)) break;
						for(int y2=y0+1;y2<=m;y2++){
							if(!check3(x2,y0,y2)){break;}
							vc++;j=x2+1;
							while(a[j][y0]==0&&j<=n){
								j++;
								vf++;
							}
						}
					}
				}
			}
		}
	printf("%d %d\n",vc*c%998244353,vf*f%998244353);
	}
	return 0;
}

2022/11/27 10:46
加载中...