第一个点WA,后面暂时都过了,问一下是为啥啊,我考场估计又犯病了,非得装,写特判
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int read(){
int x=0,sign=1;
char c=getchar();
while(c>'9'||c<'0')
{
if(c=='-')sign=-1;
c=getchar();
}
while(c<='9'&&c>='0')
{
x=x*10+c-'0';
c=getchar();
}
return x*sign;
}
long long ri[1050][1050],dow[1050][1050],c,f,n,m,t,id;
char a[1050][1050];
long long ansc,ansf;
string hh;
int main(){
freopen("plant.in","r",stdin);
freopen("plant.out","w",stdout);
t=read(),id=read();
while(t--)//记得清空
{ memset(ri,0,sizeof(ri));
memset(dow,0,sizeof(dow));
memset(a,0,sizeof(a));
ansc=0,ansf=0;
n=read(),m=read(),c=read(),f=read();
if(c==0&&f==0)
{
cout<<"0 0"<<"\n";
break;
}
for(int i=1;i<=n;i++)//行
{
cin>>hh;
for(int j=1;j<=m;j++)//列
{
a[i][j]=hh[j-1];
}
}
for(int i=n;i>=1;i--)
for(int j=m;j>=1;j--)
{
if(a[i][j]=='0')
{
ri[i][j]++,dow[i][j]++;
ri[i][j]+=ri[i][j+1];
dow[i][j]+=dow[i+1][j];
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(ri[i][j]>1&&dow[i][j]>2)
{
for(int k=i+2;k<=i+dow[i][j]-1;k++)
{
ansc+=((ri[i][j]-1)%mod*(ri[k][j]-1)%mod);
ansf+=(((ri[i][j]-1)*(ri[k][j]-1))%mod*(dow[k][j]-1))%mod;
}
}
}
ansc=(c*ansc)%mod;
ansf=(f*ansf)%mod;
cout<<ansc<<" "<<ansf<<endl;
}
cout.flush();
return 0;
}
/*
1 0
4 3 1 1
001
010
000
000
*/