12pts,做法假在哪里了,让我死个明白
查看原帖
12pts,做法假在哪里了,让我死个明白
669680
faint楼主2022/11/26 20:56
#include<bits/stdc++.h>
#define ll long long
#define re register
using namespace std;
const int maxN=1e3+5,mod=998244353;
int t,n,m,c,f,id;
bool ok[maxN][maxN];
int sum[maxN][maxN];
string s;
ll ansc,ansf;
void read(int &ls){
	int f=1;ls=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){ls=ls*10+ch-'0';ch=getchar();}
	ls*=f;
}

void vcf(int i,int j){
	if(ok[i+1][j]||ok[i+2][j]||ok[i][j+1]||sum[i+2][j]==0) return;
	int h_up=sum[i][j],h_down=0;
	for(re int u=i+3;;u++){
		if(!ok[u][j]) h_down++;
		else break;
	}
	for(re int u=i+2;!ok[u][j];u++){
		ansc+=sum[u][j]*h_up;
		if(ansc>=mod) ansc%=mod;
		if(h_down==0) break;
		if(id==15) continue;
		ansf+=sum[u][j]*h_up*h_down;
		if(ansf>=mod) ansf%=mod;
		h_down--;
	}
}

int main(){
	read(t);read(id);
	while(t--){
		ansc=0,ansf=0;
		read(n);read(m);read(c);read(f);
		for(re int i=1;i<=n;i++){
			cin>>s;
			for(re int j=0;j<m;j++){
				if(s[j]=='1')
					ok[i][j+1]=1;
			}
		}
		int ls=0;
		for(re int i=1;i<=n;i++){
			ls=0;
			for(re int j=m;j>=1;j--){
				sum[i][j]=ls;
				if(ok[i][j]) ls=0;
				else ls++;
			}
		}
		for(re int i=1;i<=n;i++) ok[i][m+1]=1;
		for(re int i=1;i<=m+1;i++) ok[n+1][i]=1;
		if(id==1){
			cout<<0<<' '<<0<<'\n';
			continue;
		}
		for(re int i=1;i<=n;i++){
			for(re int j=1;j<=m;j++){
				if(!ok[i][j]) vcf(i,j);
			}
		}
		cout<<(c*ansc)%mod<<' '<<(f*ansf)%mod<<'\n';
	}
	return 0;
}

//1 0
//4 3 1 1
//001
//010
//000
//000


2022/11/26 20:56
加载中...