注意 (m[h][l] & 1) == 0 要加括号不然会先算1==0
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
int H,L,room=0,size,MAX=0;
int m[60][60],visit[60][60];
int x[4][2]= {{-1,0},{0,1},{1,0},{0,-1}};
void dfs(int h,int l) {
if(h>=0&&h<H&&l>=0&&l<L&&visit[h][l]==0) {
visit[h][l]=1;
size++;
} else return;
if((m[h][l]&1)==0) dfs(h,l-1);
if((m[h][l]&2)==0) dfs(h-1,l);
if((m[h][l]&4)==0) dfs(h,l+1);
if((m[h][l]&8)==0) dfs(h+1,l);
}
int main() {
scanf("%d%d",&H,&L);
for(int i=0; i<H; i++) {
for(int j=0; j<L; j++) {
scanf("%d",&m[i][j]);
}
}
for(int i=0; i<H; i++) {
for(int j=0; j<L; j++) {
size=0;
dfs(i,j);
if(size>0) room++;
if(size>MAX) MAX=size;
}
}
printf("%d\n%d",room,MAX);
return 0;
}