开O2能AC
#include<bits/stdc++.h>
using namespace std;
int n,m;
int x;
int res,op,cnt;
int ans[5];
struct Node
{
int e,s,w,n;
} t[54][54];
struct que
{
int x,y;
} q[1145];
int l,r;
int st[54][54];
inline void U(int x,int y)
{
if(!st[x-1][y]&&!t[x][y].n)
{
q[r].x=x-1;
q[r++].y=y;
st[x-1][y]=1;
cnt++;
}
}
inline void D(int x,int y)
{
if(!st[x+1][y]&&!t[x][y].s)
{
q[r].x=x+1;
q[r++].y=y;
st[x+1][y]=1;
cnt++;
}
}
inline void L(int x,int y)
{
if(!st[x][y-1]&&!t[x][y].w)
{
q[r].x=x;
q[r++].y=y-1;
st[x][y-1]=1;
cnt++;
}
}
inline void R(int x,int y)
{
if(!st[x][y+1]&&!t[x][y].e)
{
q[r].x=x;
q[r++].y=y+1;
st[x][y+1]=1;
cnt++;
}
}
inline void bfs()
{
while(l<=r)
{
int x=q[l].x;
int y=q[l++].y;
if(x==0||y==0)
continue ;
//cout<<x<<' '<<y<<'\n';
if(x>=2)
U(x,y);
if(y>=2)
L(x,y);
if(x<=n-1)
D(x,y);
if(y<=m-1)
R(x,y);
}
}
inline void find()
{
res=0;
memset(st,0,sizeof st);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(!st[i][j])
{
memset(q,0,sizeof q);
cnt=1;
l=0;r=0;
q[r].x=i;
q[r++].y=j;
st[i][j]=1;
bfs();
//cout<<cnt<<'\n';
//cout<<"-----------"<<'\n';
res++;
op=max(op,cnt);
}
}
int main()
{
cin>>m>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>x;
if(x&1)
t[i][j].w=1;
if(x&2)
t[i][j].n=1;
if(x&4)
t[i][j].e=1;
if(x&8)
t[i][j].s=1;
//cout<<i<<' '<<j<<'\n';
//cout<<t[i][j].e<<' '<<t[i][j].s<<' '<<t[i][j].w<<' '<<t[i][j].n<<'\n';
}
find();
cout<<res<<'\n';
ans[0]=op;
cout<<ans[0]<<'\n';
for(int j=1;j<=m;j++)
for(int i=n;i>=1;i--)
{
if(i>=2&&t[i][j].n)
{
t[i][j].n=0;
t[i-1][j].s=0;
op=0;
find();
if(ans[0]<op)
{
ans[0]=op;
ans[1]=i;
ans[2]=j;
ans[3]=1;
}
t[i][j].n=1;
t[i-1][j].s=1;
}
if(j<=m-1&&t[i][j].e)
{
t[i][j].e=0;
t[i][j+1].w=0;
op=0;
find();
if(ans[0]<op)
{
ans[0]=op;
ans[1]=i;
ans[2]=j;
ans[3]=2;
}
t[i][j].e=1;
t[i][j+1].w=1;
}
}
cout<<ans[0]<<'\n';
cout<<ans[1]<<' '<<ans[2]<<' ';
if(ans[3]==1)
cout<<"N";
else
cout<<"E";
return 0;
}