社区讨论

奇奇怪怪的东西

P8865[NOIP2022] 种花参与者 1已保存回复 2

讨论操作

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

当前回复
2 条
当前快照
1 份
快照标识符
@mibrfnth
此快照首次捕获于
2025/11/23 21:35
3 个月前
此快照最后确认于
2025/11/23 23:06
3 个月前
查看原帖
如果你下载wa的测试点并本地可过,那么可以试试把在主函数里定义的数组放到全局定义,我这个就是。。。
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int T,id,n,m,c,f,ansc=0,ansf=0;
bool a[1005][1005];
int rt[1005][1005];
int down[1005][1005];
int cnt[1005][1005];
//int ans1[1005][1005];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T>>id;
	while(T--){
		ansc=0,ansf=0;
		cin>>n>>m>>c>>f;
//这里
		int ans1[1005][1005];
//这里
//		memset(ans1,0,sizeof(ans1));
		memset(cnt,0,sizeof(cnt));
		memset(rt,0,sizeof(rt));
		memset(down,0,sizeof(down));
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				char c;
				cin>>c;
				if(c=='1'){
					a[i][j]=1;
				}
				else{
					a[i][j]=0;
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=m;j>=1;j--){
				if(!a[i][j]){
					rt[i][j]=rt[i][j+1]+1;
				}
			}
		}
		for(int i=n;i>=3;i--){
			for(int j=1;j<=m;j++){
				if(!a[i][j]){
					down[i][j]=down[i+1][j]+1;
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(rt[i][j]>0){
					cnt[i][j]=cnt[i-1][j]+rt[i][j]-1;
					cnt[i][j]%=mod;
				}
			}
		}
		for(int i=3;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(rt[i][j]-1>0&&cnt[i][j]>0&&cnt[i-2][j]>0&&!a[i-1][j]&&!a[i-2][j]&&!a[i][j]){
					ans1[i][j]=(rt[i][j]-1)*cnt[i-2][j];
					ans1[i][j]%=mod;
					ansc+=ans1[i][j];
					ansc%=mod;
				}
				
			}
		}
		for(int i=3;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(down[i][j]-1>0){
					ansf+=ans1[i][j]*(down[i][j]-1);
					ansf%=mod;
				}
			}
		}
		
//调试 
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=m;j++){
//				cout<<rt[i][j]-1<<' ';
//			}
//			cout<<'\n';
//		}
//		cout<<"\n";
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=m;j++){
//				cout<<cnt[i][j]<<' ';
//			}
//			cout<<'\n';
//		}
//		cout<<"\n";
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=m;j++){
//				cout<<ans1[i][j]<<' ';
//			}
//			cout<<'\n';
//		}
//		cout<<"\n";
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=m;j++){
//				cout<<down[i][j]-1<<' ';
//			}
//			cout<<'\n';
//		}
//		cout<<"\n";
		cout<<ansc*c<<' '<<ansf*f<<"\n";
//		cout<<"end\n";
	}
	return 0;
}

回复

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

正在加载回复...