#include <bits/stdc++.h>
using namespace std;
const int MOD=998244353;
int T,id,n,m,c,f;
char a[1005][1005];
long long ansc,ansf,b[1005][1005],h[1005][1005],d[1005][1005];
/*
a:
001
010
000
000
b:
210
101
321
321
h:
410
303
222
111
d:
100
100
310
520
*/
int main(){
//freopen("plant5.in","r",stdin);
//freopen("plant5.out","w",stdout);
scanf("%d%d",&T,&id);
for(int t=1;t<=T;t++){
ansc=0; ansf=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(h,0,sizeof(h));
memset(d,0,sizeof(d));
scanf("%d%d%d%d",&n,&m,&c,&f);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
scanf("%c",&a[i][j]);
if(a[i][j]=='\n')
scanf("%c",&a[i][j]);
}
for(int i=0;i<n;i++)
for(int j=m-1;j>=0;j--)
if(a[i][j]=='0'||a[i][j]==0)
b[i][j]=b[i][j+1]+1;
else
b[i][j]=0;
for(int j=0;j<m;j++)
for(int i=n-1;i>=0;i--)
if(a[i][j]=='0'||a[i][j]==0)
h[i][j]=h[i+1][j]+1;
else
h[i][j]=0;
for(int j=0;j<m;j++)
for(int i=0;i<n;i++){
if(a[i][j]=='0'||a[i][j]==0)
d[i][j]=d[i-1][j]+b[i][j]-1;
else
d[i][j]=0;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(i>=2&&/*!!!*/a[i][j]=='0'/*!!!*/&&a[i-1][j]=='0'&&a[i-2][j]=='0'){
long long DDG=(d[i][j]-b[i][j]-b[i-1][j]+2)%MOD*(b[i][j]-1)%MOD;
ansc=(ansc+DDG)%MOD;
ansf=(ansf+DDG*(h[i][j]-1)%MOD)%MOD;
}
//cout<<i<<" "<<j<<" "<<ansc<<" "<<ansf<<endl;
}
}
/*
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
printf("%d ",d[i][j]);
printf("\n");
}
*/
printf("%lld %lld\n",(long long)c*ansc%MOD,(long long)f*ansf%MOD);
}
return 0;
}
例如在Sub1#3的WA信息显示
Wrong answer.wrong answer on Line 1 column 1, read 9, expected 3
但是本地跑出的结果是和官方数据plant3.ans一样的?
求调