DCP-3: Maze Tester

Dev Skill archived problems can be discussed here.

DCP-3: Maze Tester

by Subhashis » Tue Mar 07, 2017 3:14 am

why i get runtime error??
please help

#include<bits/stdc++.h>
#define fr(i,m) for(int i=0;i<m;i++)
using namespace std;
long dx[]= {-1,0,0,1};
long dy[]= {0,-1,1,0};
string s[100];
long vis[100][100]={0},flag,cnt=0;
long bfs(long x,long y)
{
long x1,y1,i1;
vis[x][y]=1;
for(i1=0;i1<5;i1++)
{
x1=x+dx[i1];
y1=y+dy[i1];
// cout<<x1<<" "<<y1<<" "<<s[x1][y1];
if((vis[x1][y1]==0)&&(x1>=0&&x1<30)&&(y1>=0&&y1<30)&&((s[x1][y1]=='.')||(s[x1][y1]=='G')))
{
cnt++;
if(s[x1][y1]=='G')
{
flag=1;
break;
}
if(cnt>900)
break;
vis[x1][y1]=1;
s[x1][y1]='*';
bfs(x1,y1);
}
}
return flag;
}
main()
{
while(1)
{
long i,j;
for(i=0; i<30; i++)
{
cin>>s[i];
}
long ans=0;
for(i=0; i<30; i++)
{
for(j=0; j<30; j++)
{
if(s[i][j]=='P')
{
flag=0;
cnt=0;
ans=bfs(i,j);
}
}
}
if(ans==1)
{
cout<<"Possible"<<endl;
}
else
cout<<"Impossible"<<endl;
for(i=0;i<30;i++)
{
for(j=0;j<30;j++)
vis[i][j]=0;
}
}
}
 
Posts: 2
Joined: Tue Mar 07, 2017 3:06 am

Who is online
Users browsing this forum: No registered users and 1 guest
cron