蒟蒻自己看了好久都觉得没问题,但样例都过不了(始终NEVER)
#include<bits/stdc++.h>
using namespace std;
const int N=1000;
const int DCT=8;
int mx[DCT]={0 , 1 , 0 , -1 , 1 , -1 , 1 , -1};
int my[DCT]={0 , 1 , 0 , -1 , 1 , -1 , 1 , -1};
long long mh[N][N],mape[N][N][8];
int n,m;
struct NODE{
int x;
int y;
int step;
int f;
};
NODE dt[N];
void dg(int x,int y)
{
NODE h,next;
int head=0,tail=0;
// mape[y][x]=1;
dt[++tail]={x,y,0,-1};
while(head<tail){
h=dt[++head];
for(int i=0;i<DCT;i++)
{
next.x=h.x+mh[h.y][h.x]*mx[i];
next.y=h.y+mh[h.y][h.x]*my[i];
next.step=h.y+1;
next.f=i;
if(next.x>=1 && next.x<=n && next.y>=1 && next.y<=m&& mape[next.y][next.x][next.f]==0)
{
dt[++tail]=next;
mape[next.y][next.x][next.f]=1;
if(next.x==n && next.y==m)
{
cout<<dt[tail].step;
return;
}
}
}
}
cout<<"NEVER";
return;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
cin>>mh[i][j];
}
}
dg(1,1);
return 0;
}