社区讨论

P8865 种花 求助

灌水区参与者 5已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@m52gwgwt
此快照首次捕获于
2024/12/24 20:54
去年
此快照最后确认于
2025/11/04 12:23
4 个月前
查看原帖
题目链接
评测记录
TLE该怎么该
有没有能优化的地方
加快读有救吗
代码附上
CPP
#include <bits/stdc++.h>
using namespace std;
const int N=998244353;
long long W,n,m,c,f,Zn[1005][1005][2],sb,k,an1,an2;
char Ag[1005][1005];
int main(){
	ios::sync_with_stdio(false);
	cin>>W>>sb;
	for(int i=0;i<W;i++){
		cin>>n>>m>>c>>f;
		c=c%N,f=f%N,an1=0,an2=0;
		for(int i=0;i<n+2;i++){
			for(int j=0;j<m+2;j++){
				Zn[i][j][0]=0,Zn[i][j][1]=0;
				if(i==0||j==0||i==n+1||j==m+1) Ag[i][j]='1';
				else cin>>Ag[i][j];
			}
		}
		if(c==0&&f==0){
			cout<<0<<' '<<0<<endl;
			continue;
		} 
		for(int i=1;i<=n;i++)
			for(int j=m;j>0;j--)
				if(Ag[i][j]=='0') Zn[i][j][0]=Zn[i][j+1][0]+1;
		for(int i=n;i>0;i--)
			for(int j=1;j<=m;j++)
				if(Ag[i][j]=='0') Zn[i][j][1]=Zn[i+1][j][1]+1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(Ag[i][j]=='0'&&Ag[i+1][j]=='0'){
					k=i+2;
					while(Ag[k][j]=='0'){
						an1+=((Zn[k][j][0]-1)*(Zn[i][j][0]-1))%N;
						an2+=((Zn[k][j][0]-1)*(Zn[i][j][0]-1)*(Zn[k][j][1]-1))%N;
						an1%=N,an2%=N;
						k++;
					}
				}
			}
		}
		cout<<(an1*c)%N<<" "<<(an2*f)%N<<endl;
	}
}

回复

4 条回复,欢迎继续交流。

正在加载回复...