题目链接:点击这里
输入的 ,本想着开一堆数组预处理一下所有格子周围的墙,二进制的表示是真的巧。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define r first
#define c second
using namespace std;
typedef pair<int,int> PII;
const int N = 55, M = N * N;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int n, m;
int a[N][N];
bool st[N][N];
PII q[M];
int bfs(int x, int y)
{
int hh = 0, tt = -1;
int area = 0;
q[++tt] = {x, y};
st[x][y] = true;
while(hh <= tt)
{
PII t = q[hh++];
area++;
for(int i = 0; i < 4; ++i)
{
int nx = t.r + dx[i], ny = t.c + dy[i];
if(nx < 1 || nx > n || ny < 1 || ny > m) continue;
if(st[nx][ny]) continue;
if(a[t.r][t.c] >> i & 1) continue;
q[++tt] = {nx, ny};
st[nx][ny] = true;
}
}
return area;
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
scanf("%d", &a[i][j]);
int cnt = 0;
int maxx = 0;
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= m; ++j)
{
if(!st[i][j])
{
maxx = max(maxx, bfs(i, j));
cnt++;
}
}
}
printf("%d\n%d\n", cnt, maxx);
return 0;
}