110 lines
2.6 KiB
C++
110 lines
2.6 KiB
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
using ll = int64_t;
|
|
|
|
const ll maxn{ll(1e3+5)}, mod{998244353};
|
|
ll t,id,n,m,c,f,tmp,tor[maxn][maxn],totc,tou[maxn][maxn],ptor[maxn][maxn],totf,tod[maxn][maxn];
|
|
bitset<maxn> g[maxn];
|
|
string s;
|
|
|
|
template<class ...Args>
|
|
void pt(Args&&...args){
|
|
((cout<<std::forward<Args>(args)<<' '),...);
|
|
cout<<'\n';
|
|
}
|
|
|
|
template<class T,class P>
|
|
ostream&operator<<(ostream &os,const pair<T,P> &p){
|
|
cout<<"[DEBUG] "<<"( "<<p.first<<", "<<p.second<<" )";
|
|
return os;
|
|
}
|
|
|
|
void pnm(const ll (&a)[maxn][maxn]){
|
|
for(ll i{1};i<=n;i++){
|
|
cout<<"[DEBUG] ";
|
|
for(ll j{1};j<=m;j++){
|
|
cout<<a[i][j]<<' ';
|
|
}
|
|
cout<<'\n';
|
|
}
|
|
cout<<'\n';
|
|
}
|
|
|
|
int main(){
|
|
iostream::sync_with_stdio(0),cin.tie(0),cout.tie(0);
|
|
|
|
cin>>t>>id;
|
|
while(t--){
|
|
cin>>n>>m>>c>>f;
|
|
totc=0;
|
|
totf=0;
|
|
// pt(n,m,c,f);
|
|
for(ll i{1};i<=n;i++){
|
|
cin>>s;
|
|
for(ll j{1};j<=m;j++){
|
|
g[i][j]=s[j-1]-'0';
|
|
// pt(g[i][j]);
|
|
}
|
|
}
|
|
|
|
// look right
|
|
for(ll i{1};i<=n;i++){
|
|
tor[i][m+1]=0;
|
|
for(ll j{m};j>=0;j--){
|
|
if(g[i][j]){
|
|
tor[i][j]=0;
|
|
ptor[i][j]=0;
|
|
}else{
|
|
tor[i][j]=tor[i][j+1]+1;
|
|
ptor[i][j]=ptor[i-1][j]+max(ll(0),tor[i][j]-1);
|
|
}
|
|
}
|
|
}
|
|
// pnm(tor);
|
|
// pnm(ptor);
|
|
|
|
//look up
|
|
for(ll j{1};j<=m;j++){
|
|
tou[0][j]=0;
|
|
for(ll i{1};i<=n;i++){
|
|
if(g[i][j]){
|
|
tou[i][j]=0;
|
|
}else{
|
|
tou[i][j]=tou[i-1][j]+1;
|
|
}
|
|
}
|
|
}
|
|
// pnm(tou);
|
|
|
|
//look down
|
|
for(ll j{1};j<=m;j++){
|
|
tod[n+1][j]=0;
|
|
}
|
|
for(ll i{n};i>=0;i--){
|
|
for(ll j{1};j<=m;j++){
|
|
if(g[i][j]){
|
|
tod[i][j]=0;
|
|
}else{
|
|
tod[i][j]=tod[i+1][j]+1;
|
|
}
|
|
}
|
|
}
|
|
// pnm(tod);
|
|
|
|
for(ll j{1};j<m;j++){
|
|
for(ll i{3};i<=n;i++){
|
|
if(
|
|
tor[i][j]>=2&&tou[i][j]>=3
|
|
){
|
|
// cout<<make_pair(i,j)<<'\n';
|
|
totc = (totc+(ptor[i-2][j]*(tor[i][j]-1))%mod)%mod;
|
|
if(tod[i][j]-1>0){
|
|
totf = (totf+(ptor[i-1][j]*(tor[i][j]-1)*(tod[i][j]-1))%mod)%mod;
|
|
}
|
|
// pt(totc,totf);
|
|
}
|
|
}
|
|
}
|
|
cout<<totc<<' '<<totf<<'\n';
|
|
}
|
|
} |