檢查不出為什麼最後一題會RE,可以請各位大老幫忙看一下嗎
#include<bits/stdc++.h>
using namespace std;
pair<pair<bool,bool>,pair<bool,bool>> a[1000][1000];
bool used[1000][1000]={0};
int maze(int x,int y)
{
int num=0;
num++;
used[x][y]=1;
if(a[x][y].first.first&&a[x-1][y].first.second&&!(used[x-1][y])) num+=maze(x-1,y);
if(a[x][y].first.second&&a[x+1][y].first.first&&!(used[x+1][y])) num+=maze(x+1,y);
if(a[x][y].second.first&&a[x][y-1].second.second&&!(used[x][y-1]))num+=maze(x,y-1);
if(a[x][y].second.second&&a[x][y+1].second.first&&!(used[x][y+1])) num+=maze(x,y+1);
return num;
}
int main()
{
int m,n;
cin >> m >> n;
for(int i=0;i<=m+1;i++)
{
for(int j=0;j<=n+1;j++)
{
if(i==0||i==m+1||j==0||j==n+1)
{
a[i][j]={{0,0},{0,0}};
used[i][j]=1;
continue;
}
char q;
cin >> q;
if(q=='X') a[i][j]={{1,1},{1,1}};
else if(q=='H') a[i][j]={{0,0},{1,1}};
else if(q=='I') a[i][j]={{1,1},{0,0}};
else if(q=='F') a[i][j]={{0,1},{0,1}};
else if(q=='L') a[i][j]={{1,0},{0,1}};
else if(q=='J') a[i][j]={{1,0},{1,0}};
else if(q=='7') a[i][j]={{0,1},{1,0}};
else{ a[i][j]={{0,0},{0,0}}; used[i][j]=1;}
}
}
int cnt=0;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
if(!(used[i][j])) cnt=max(cnt,maze(i,j));
}
}
cout << cnt;
}