why all tle?why all tle?why all tle?
查看原帖
why all tle?why all tle?why all tle?
311306
dk_qwq楼主2022/11/26 19:07
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define mod (ll)(998244353)
using namespace std;
namespace INPUT{
	char buf[1<<20],*p1,*p2;
	#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin)),p1==p2?EOF:*p1++)
}
using namespace INPUT;
template<typename T>
inline T read(){
	T x=0,p=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') p=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*p;
}
typedef long long ll;
const int N=1005;
int ma[N][N];
int f1[N][N],f2[N][N];
int have_1[N][N];
int n,m;
ll c,f;
ll ans;
void solve(){
	memset(f1,0,sizeof(f1));
	memset(f2,0,sizeof(f2));
	memset(have_1,0,sizeof(have_1));
	n=read<int>(),m=read<int>();
	c=read<ll>(),f=read<ll>();
	ans=0;
	for(int i=1;i<=n;i++){
		char ch=gc();
		while(ch<'0'||ch>'9') ch=gc();
		ma[i][1]=(ch=='1');
		for(int j=2;j<=m;j++) ma[i][j]=(gc()=='1');
	}
	for(int i=1;i<=n;i++) for(int j=m;j>=1;j--)
		if(!ma[i][j]) f1[i][j]=f1[i][j+1]+1;
	for(int j=1;j<=m;j++) for(int i=n;i>=1;i--)
		if(!ma[i][j]) f2[i][j]=f2[i+1][j]+1;
	for(int j=1;j<=m;j++) for(int i=n;i>=1;i--)
		have_1[i][j]=have_1[i+1][j]+(ma[i][j]==1);
	//find C
	//x_1+1<x_2 y_0< y_1,y_2
	for(int x_1=1;x_1<=n;x_1++){
		for(int x_2=x_1+2;x_2<=n;x_2++){
			for(int y_0=1;y_0<=m;y_0++){
				if(have_1[x_1][y_0]-have_1[x_2+1][y_0]) continue;
				if(f1[x_1][y_0]<2||f1[x_2][y_0]<2) continue;
				ans=((ll)(f1[x_1][y_0]-1)*(f1[x_2][y_0]-1)%mod+ans)%mod;
			}
		}
	}
	printf("%lld ",ans*c%mod);
	ans=0;
	//find F
	//x_1+1<x_2<x_3 y_0< y_1,y_2
	for(int x_1=1;x_1<=n;x_1++){
		for(int x_2=x_1+2;x_2<=n;x_2++){
			for(int y_0=1;y_0<=m;y_0++){
				if(have_1[x_1][y_0]-have_1[x_2+1][y_0]) continue;
				ans=((ll)(f1[x_1][y_0]-1)*(f1[x_2][y_0]-1)%mod*(f2[x_2][y_0]-1)%mod+ans)%mod;
			}
		}
	}
	printf("%lld",ans*f%mod);
	puts("");
}
int main() {
//	freopen("plant.in","r",stdin);
//	freopen("plant.out","w",stdout);
	int T=read<int>(),id=read<int>();
	while(T--) solve();
	return 0;
}
2022/11/26 19:07
加载中...