1分 求调TvT
查看原帖
1分 求调TvT
1037550
lucas_s楼主2023/10/22 17:16
#include<bits/stdc++.h>
using namespace std;

const int N=1e3+10;
const int MOD=998244353;
char mp[N][N];
int Right[N][N];
int Down[N][N];

int T,id;//组数 测试点编号 
int n;//行 
int m;//列
int f,c; 
int ansc;//C的有多少种摆法
int ansf;//F的有多少种摆法 

int main(){
	ios::sync_with_stdio(false),cin.tie(0);
	freopen("plant1.in","r",stdin);
	cin >> T >> id;
	
	for(int k=1;k<=T;k++){
		cin >> n >> m >> c >> f; 
		memset(mp,0,sizeof(mp));
		memset(Right,0,sizeof(Right));
		memset(Down,0,sizeof(Down));
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++){
				cin >> mp[i][j];
				if(mp[i][j]=='0'){
					Right[i][j-1]++;
					Down[i-1][j]++;	
				}
			}

		for(int i=n;i>=1;i--){
			for(int j=m;j>=1;j--){
				if(mp[i][j]=='1'){
					Right[i][j]=0;
					Down[i][j]=0;
					continue;
				}
				Right[i][j]=Right[i][j]+Right[i][j+1];
				Down[i][j]=Down[i][j]+Down[i+1][j];
			}
		}
	
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				int r=Right[i][j];
				int d=Down[i][j];
				if(r==0 || d==0 || d==1) continue;
				for(int a=i+2;a<=i+d;a++){
					int r1=Right[a][j];
					ansc+=r*r1;
					ansf+=r*r1*Down[a][j];
				}
			}
		}
		cout << (c*ansc)%MOD << " " << (f*ansf)%MOD << endl;
	}
}
2023/10/22 17:16
加载中...