记录编号 581786 评测结果 AAAAAAAAAAAAAWAW
题目名称 [NOIP 2022]种花 最终得分 78
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 未通过
代码语言 C++ 运行时间 2.087 s
提交时间 2023-08-13 09:23:09 内存使用 77.23 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 2100,mod = 998244353;
int T,id,n,m,C,F;
long long r[N][N],ansc,ansf,s[N][N];
bool v[N][N];
char ch;
void first(){
    ansc = ansf = 0;
	memset(r,0,sizeof(r));
	memset(v,0,sizeof(v));
}
void init(){
	scanf("%d%d%d%d",&n,&m,&C,&F);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			cin>>ch;
			v[i][j] = (ch == '1');
		}
	}
}
int main(){
	freopen("noip2022_plant.in","r",stdin);
	freopen("noip2022_plant.out","w",stdout);
	scanf("%d%d",&T,&id);
	while(T--){
		first();
		init();
		for(int i = 1;i <= n;i++){
			r[i][m+1] = -1;
			for(int j = m;j >= 1;j--){
				if(!v[i][j])r[i][j] = r[i][j+1]+1;
				else r[i][j] = -1;
			}
		}
		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= m;j++){
				if(v[i][j] || v[i+1][j])continue;
				for(int k = i+2;k <= n && !v[k][j];k++){
					(ansc += (r[i][j] * r[k][j]) % mod) % mod;
				}
			}
		}
		for(int j = 1;j <= m;j++){
			s[n+1][j] = -1;
			for(int i = n;i >= 1;i--){
				if(!v[i][j])s[i][j] = s[i+1][j] + 1;
				else s[i][j] = -1;
			}
		}
		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= m;j++){
				if(v[i][j] || v[i+1][j])continue;
				for(int k = i+2;k <= n && !v[k][j];k++){
					(ansf += (r[i][j] * (r[k][j] * s[k][j]) % mod) % mod) % mod;
				}
			}
		}
		printf("%lld %lld\n",ansc*C,ansf*F);
	}
	
	return 0;
	
}