爆搜
#include<bits/stdc++.h>
using namespace std;int nn,m;
int tot=0,sum[5000],//极端情况下会有50*50个房间
a[1000][1000],w[1000][1000],n[1000][1000],e[1000][1000],s[1000][1000],f[1000][1000];
void dfs(int x,int y)
{
if(y<=0||x<=0||x>nn||y>m) return;//不解释了注意一下QAQ
sum[tot]++;
f[x][y]=tot;
if(!s[x][y]&&!f[x+1][y]) dfs(x+1,y);
if(!e[x][y]&&!f[x][y+1]) dfs(x,y+1);
if(!n[x][y]&&!f[x-1][y]) dfs(x-1,y);
if(!w[x][y]&&!f[x][y-1]) dfs(x,y-1);
}
int main()
{
cin>>m>>nn;
for(int i=1;i<=nn;i++)
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j]>=8) s[i][j]=1;
a[i][j]%=8;
if(a[i][j]>=4) e[i][j]=1;
a[i][j]%=4;
if(a[i][j]>=2) n[i][j]=1;
a[i][j]%=2;
if(a[i][j]==1) w[i][j]=1;
}
int maxn=0,ansi,ansj;
char anss;
for(int i=1;i<=nn;i++)
for(int j=1;j<=m;j++)
{
if(!f[i][j])
{
tot++;
dfs(i,j);
maxn=max(maxn,sum[tot]);
}
}
cout<<tot<<"
"<<maxn<<"
";
for(int j=1;j<=m;j++)
for(int i=nn;i>=1;i--)//对顺序有要求
{
//不能推外墙
if(j-1>=1&&w[i][j]&&f[i][j-1]!=f[i][j]&&maxn<sum[f[i][j-1]]+sum[f[i][j]]) maxn=sum[f[i][j-1]]+sum[f[i][j]],ansi=i,ansj=j,anss='W';
if(i+1<=nn&&s[i][j]&&f[i+1][j]!=f[i][j]&&maxn<sum[f[i+1][j]]+sum[f[i][j]]) maxn=sum[f[i+1][j]]+sum[f[i][j]],ansi=i,ansj=j,anss='S';
if(i-1>=1&&n[i][j]&&f[i-1][j]!=f[i][j]&&maxn<sum[f[i-1][j]]+sum[f[i][j]]) maxn=sum[f[i-1][j]]+sum[f[i][j]],ansi=i,ansj=j,anss='N';
if(j+1<=m&&e[i][j]&&f[i][j+1]!=f[i][j]&&maxn<sum[f[i][j+1]]+sum[f[i][j]]) maxn=sum[f[i][j+1]]+sum[f[i][j]],ansi=i,ansj=j,anss='E';
//注意题目中对四个方向的优先级有要求
}
cout<<maxn<<"
"<<ansi<<" "<<ansj<<" "<<anss;
return 0;
}