86pts subtask #0 #32 WA求调
查看原帖
86pts subtask #0 #32 WA求调
1000268
PassionOfLife楼主2023/10/29 16:22

只有 subtask #0 #32 这个点没过,代码如下

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e3+10;
const int M = 1e3+10;
const int BIG = 998244353;

int a[N][M]; 
int r[N][M]; 
int d[N][M]; 
int n, m, c, f;
int T, id;
int ansC, ansF;

int readchar() {
	for(;;) {
		int ch = getchar();
		if(ch != '\n' && ch != '\r')	return ch;
	}
}

void init_() {
	memset(a, 0, sizeof(a));
	scanf("%d%d%d%d", &n, &m, &c, &f);
	for(int i = 1; i<=n; i++)
		for(int j = 1; j<=m; j++)
			a[i][j] = readchar() - '0';
	
	for(int i = 1; i<=n; i++) {
		r[i][m+1] = 0;
		for(int j = m; j>=1; j--)
			r[i][j] = (a[i][j] == 1 ? 0 : r[i][j+1] + 1); //Ò»°ã´¦Àí 
	}
	
	for(int j = 1; j<=m; j++) {
		d[n+1][j] = 0;
		for(int i = n; i>=1; i--)
			d[i][j] = (a[i][j] == 1 ? 0 : d[i+1][j] + 1);
	}
}

void getAns() {
	ansC = ansF = 0;
	
	for(int y0 = 1; y0 <= m; y0++) {
		int sum = 0;
		for(int x = 1; x <= n; x++) {
			if(x >= 3 && a[x][y0] == 0 && a[x-1][y0] == 0 && a[x-2][y0] == 0) {
				ansC = (ansC + sum*(r[x][y0] - 1)) % BIG;
				ansF = (ansF + sum*(r[x][y0] - 1)*(d[x][y0] - 1)) % BIG;
			}
			
			if(a[x][y0] == 1)	sum = 0;
			else				sum += max(0, r[x-1][y0] - 1) % BIG;
		}
	}
}

int main() {
	scanf("%d%d", &T, &id);
	while(T--) {
		init_();
		getAns();
		printf("%d %d\n", c*ansC, f*ansF);
	}
	return 0;
}
2023/10/29 16:22
加载中...