```cpp
int main()
{
n=read();
for(long long i=1;i<=n;i++)
{
for(long long j=1;j<=n;j++)
{
mp[i][j]=get_bool();
}
}
st.input();
ed.input();
if(st==ed)
{
printf("0\n");
exit(0);
}
if(true)
{
step young;
young.now=st;
young.passed=0;
que.push(young);
young.now.bookit();
}
while(!que.empty())
{
for(long long i=1;i<=4;i++)
{
if(i==1)
{
step young;
young.now=que.front().now+up;
young.passed=que.front().passed+1;
if(!young.now.booked())
{
if(young.now.can())
{
if(young.now==ed)
{
printf("%lld\n",young.passed);
exit(0);
}
que.push(young);
young.now.bookit();
}
}
}
if(i==2)
{
step young;
young.now=que.front().now+dn;
young.passed=que.front().passed+1;
if(!young.now.booked())
{
if(young.now.can())
{
if(young.now==ed)
{
printf("%lld\n",young.passed);
exit(0);
}
que.push(young);
young.now.bookit();
}
}
}
if(i==3)
{
step young;
young.now=que.front().now+l;
young.passed=que.front().passed+1;
if(!young.now.booked())
{
if(young.now.can())
{
if(young.now==ed)
{
printf("%lld\n",young.passed);
exit(0);
}
que.push(young);
young.now.bookit();
}
}
}
if(i==4)
{
step young;
young.now=que.front().now+r;
young.passed=que.front().passed+1;
if(!young.now.booked())
{
if(young.now.can())
{
if(young.now==ed)
{
printf("%lld\n",young.passed);
exit(0);
}
que.push(young);
young.now.bookit();
}
}
}
}
que.pop();
}
return 0;
}
bool get_bool()
{
char p;
while(true)
{
p=getchar();
if(p=='0')
{
return false;
}
if(p=='1')
{
return true;
}
}
}
inline long long read()
{
long long val=0,flag=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))
{
ch=getchar();
}
while(ch=='-')
{
flag=-flag,ch=getchar();
}
while(ch>='0'&&ch<='9')
{
val=(val << 1)+(val << 3)+ch-'0',ch=getchar();
}
return val*flag;
}
```
by 洛必达法则 @ 2018-12-22 16:31:13