NOIP T1 5分求助
  • 板块学术版
  • 楼主zrt090604
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/11/26 18:30
  • 上次更新2023/10/27 01:23:13
查看原帖
NOIP T1 5分求助
459188
zrt090604楼主2022/11/26 18:30
#include<bits/stdc++.h>
using namespace std;
int t, id, n, m, a[1005][1005], h[1005][1005], z[1005][1005], mod = 998244353;
int main () {
	scanf("%d%d", &t, &id);
	while(t--) {
		int c, f, ansc = 0, ansf = 0;
		scanf("%d%d%d%d", &n, &m, &c, &f);
		if(c==0 && f==0) {printf("0"); continue;}
		for(int i = 1;i <= n;++i)
			for(int j = 1;j <= m;++j)
				scanf("%1d", &a[i][j]);
		for(int i = 1;i <= n;++i) {
			int pos = 1, now = 1;
			while(now <= m) {
				if(a[i][now] == 1) {
					for(int j = now-1;j >= pos;--j) h[i][j] = now-j;
					pos = now+1;
				}
				++now;
			}
			for(int j = now;j >= pos;--j) h[i][j] = now-j;
		}
		for(int i = 1;i <= m;++i) {
			int pos = 1, now = 1;
			while(now <= n) {
				if(a[now][i] == 1) {
					for(int j = now-1;j >= pos;--j) z[j][i] = now-j;
					pos = now+1;
				}
				++now;
			}
			for(int j = now;j >= pos;--j) z[j][i] = now-j;
		}
		for(int i = 1;i <= n;++i)
			for(int j = 1;j <= m;++j) {
				if(h[i][j]<2 || z[i][j]<2 || a[i+1][j]) continue;
				for(int k = i+2;a[k][j]==0 && k<=n;++k) {
					if(h[k][j]>=2) ansc = (ansc + (h[i][j]-1)*(h[k][j]-1)) % mod;
					if(z[k][j]>=2) ansf = (ansf + (h[i][j]-1)*(h[k][j]-1)*(z[k][j]-1)) % mod;
				}
			}
		printf("%d %d\n", ansc*c, ansf*f);
	}
	return 0;
}
2022/11/26 18:30
加载中...