#include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0;i pii; typedef vector vi; typedef vector vvi; const int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; int N,V,Ox,Oy; int L[256][256]; int t[256][256][2]; //t[i][j][k] : (i,j)に体力t[i][j][k]でたどり着ける(kが0の時泉未使用) struct node{ int x,y,hp; bool used; }; bool ok(int x,int y){ if(0<=x and x> N >> V >> Ox >> Oy; Ox--;Oy--; REP(i,N) REP(j,N) cin >> L[i][j]; REP(i,N) REP(j,N) REP(k,2) t[i][j][k] = 0; queue que; que.push(node{0,0,V,false}); t[0][0][0] = V; while(!que.empty()){ node p = que.front(); que.pop(); const int x = p.x; const int y = p.y; const int hp = p.hp; const bool used = p.used; assert(hp>0); if(x==N-1 and y==N-1){ cout << "YES" << endl; return 0; } if(t[x][y][used]>hp) continue; REP(idx,4){ const int nx = x + dx[idx], ny = y + dy[idx]; if(!ok(nx,ny)) continue; if(hp-L[nx][ny]<0) continue; if(nx==Ox and ny==Oy and used==false){ //泉使用 if(t[nx][ny][1]<(hp-L[nx][ny])*2){ t[nx][ny][1] = (hp-L[nx][ny])*2; que.push(node{nx,ny,t[nx][ny][1],true}); } } else{ if(t[nx][ny][used]