QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#765539#7733. Cool, It’s Yesterday Four Times MoreyaotianhaoRE 0ms0kbC++142.3kb2024-11-20 14:35:332024-11-20 14:35:33

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 14:35:33]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-20 14:35:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int t, n, m, dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}, ans, p[N], b[N][N];
char a[N][N];
bool fl[N][N], f[N];
int s(int x, int y) {
	return (x - 1) * m + y;
}
struct node {
	int x, y;
};
queue <node> q;
void bfs(int id, int x, int y) {
	fl[id][s(x, y)] = 1;
	q.push({x, y});
	while(!q.empty()) {
		int nwx = q.front().x, nwy = q.front().y;
		q.pop();
		for(int i = 0; i < 4; i++) {
			int xx = nwx + dx[i], yy = nwy + dy[i];
			if(fl[id][s(xx, yy)]) continue;
			if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == '.') {
				fl[id][s(xx, yy)] = 1;
				q.push({xx, yy});
			}
		}
	}
}
signed main() {
	freopen("kangaroo.in", "r", stdin);
	freopen("kangaroo.out", "w", stdout);
	scanf("%d", &t);
	while(t--) {
		ans = 0;
		for(int i = 1; i <= n * m; i++) for(int j = 1; j <= n * m; j++) fl[i][j] = 0;
		scanf("%d%d", &n, &m);
		for(int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(a[i][j] == '.') {
			int id = s(i, j);
			p[id] = 0;
			for(int x = 1; x <= n; x++) for(int y = 1; y <= m; y++) if((i != x || j != y) && a[x][y] == '.') b[id][++p[id]] = s(x, y); 
			bfs(id, i, j);
		}
//		for(int i = 1; i <= n * m; i++) for(int j = 1; j <= p[i]; j++) printf("%d %d\n", i, b[i][j]);
		for(int cyx = -n; cyx <= n; cyx++) for(int gmx = -m; gmx <= m; gmx++) {
			for(int x = 1; x <= n; x++) for(int y = 1; y <= m; y++) if(a[x][y] == '.') {
				int xx = x + cyx, yy = y + gmx;
				if(xx < 1 || xx > n || yy < 1 || yy > m) {
					f[s(x, y)] = 0;
					continue;
				}
				if(a[xx][yy] != '.' || !fl[s(x, y)][s(xx, yy)]) {
					f[s(x, y)] = 0;
					continue;
				}
				f[s(x, y)] = 1;
//				printf("%d %d %d %d\n", cyx, gmx, x, y);
			}
			for(int i = 1; i <= n * m; i++) if(f[i]) {
				int q = 0;
				for(int j = 1; j <= p[i]; j++) if(f[b[i][j]]) b[i][++q] = b[i][j];
//				printf("%d %d %d %d\n", cyx, gmx, i, q);
				p[i] = q;
			}
		}
//		for(int i = 1; i <= n * m; i++) for(int j = 1; j <= p[i]; j++) printf("%d %d\n", i, b[i][j]);
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(a[i][j] == '.' && !p[s(i, j)]) ans++/*, printf("%d %d\n", i, j)*/;
		printf("%d\n", ans);
	}
}/*
1
1 3
.O.
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO

output:


result: