86分&&WA#32求调
查看原帖
86分&&WA#32求调
766035
xhn2077楼主2025/7/26 09:06
#include<bits/stdc++.h>
using namespace std;
long long n,m,c,f,T,d;
long long p=0,o=0,cnt=0,fnt=0;
long long k;
char a[1010][1010];
long long high[1010][1010],wide[1010][1010],fl[1010][1010],cl[1010][1010];
int main(){
//	freopen("plant16.in","r",stdin);
//	freopen ("plant16.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>T>>d;
	for(int i=1;i<=T;i++){
		cin>>n>>m>>c>>f;
		memset(a,0,sizeof(a));
		memset(high,0,sizeof(high));
		memset(wide,0,sizeof(wide));
		memset(fl,0,sizeof(fl));
		memset(cl,0,sizeof(cl));
		int p=0,o=0,cnt=0,fnt=0;
		for(int j=0;j<=n-1;j++){
			cin>>a[j];
		}
		for(int j=0;j<n;j++){
			o=0;
			for(int t=m-1;t>=0;t--){
				if(a[j][t]=='1'){
					o=0;
				}else{
					o++;
				}
				wide[j][t]=o;
				cl[j][t]=o;
			}
		}
		for(int j=0;j<m;j++){
			p=0;
			for(int t=n-1;t>=0;t--){
				if(a[t][j]=='1'){
					p=0;
				}else{
					p++;  
				}
    			high[t][j]=p;
			}
		}
		for(int j=n-1;j>=0;j--){ 
			for(int t=m-1;t>=0;t--){
				if(a[j][t-1]!='1'&&a[j+1][t-1]!='1'){
				    cl[j][t]+=cl[j+1][t];
				}
				if(a[j][t]!='1'&&a[j+1][t]!='1'&&j!=n-1&&j>1){
				    fl[j][t]=(high[j][t]-1)*wide[j][t+1]+fl[j+1][t];
				    //cout<<high[t][j]<<" "<<wide[t][j+1]<<" "<<fl[t+1][j]<<endl;
				}
			}
		}  
		for(int j=0;j<n;j++){ 
			for(int t=0;t<m;t++){
				if(high[j][t]>=3){
				    cnt+=wide[j][t+1]*cl[j+2][t+1];
				    cnt=(c*cnt)%998244353;
				    //cout<<j<<" "<<wide[j][t+1]<<" "<<t<<" "<<cl[j+2][t+1]<<" "<<cnt<<endl;
				}
				if(high[j][t]>=4){
				    fnt+=fl[j+2][t]*wide[j][t+1];
				    fnt=(f*fnt)%998244353;
				    //cout<<high[t][j]<<" "<<wide[t][j+1]<<" "<<fl[t+1][j]<<endl;
				}
			}
		}
		long long cc=(c*cnt)%998244353,ff=(f*fnt)%998244353;
        cout<<cc<<" "<<ff<<endl;
    }
	return 0;
}                      
2025/7/26 09:06
加载中...