#include #include #include #include #include #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl using namespace std; typedef long long int lli; template vector make_v(size_t a, T b) { return vector(a, b); } template auto make_v(size_t a, Ts... ts) { return vector(a, make_v(ts...)); } struct Edge { int x, y, hp, o; Edge(int _x, int _y, int h, int _o) : x(_x), y(_y), hp(h), o(_o) {} Edge() {} bool operator<(const Edge &e) const { return hp < e.hp; } }; int main() { int N, V, Ox, Oy; cin >> N >> V >> Ox >> Oy; auto L = make_v(N + 2, N + 2, -1); REP(i, 1, N + 1) { REP(j, 1, N + 1) { cin >> L[i][j]; } } priority_queue> pq; pq.emplace(1, 1, V, 0); auto used = make_v(N + 2, N + 2, 2, false); auto Cost = make_v(N + 2, N + 2, 2, 0); const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; while (pq.size()) { auto E = pq.top(); pq.pop(); if (used[E.y][E.x][E.o]) continue; used[E.y][E.x][E.o] = true; if (Cost[E.y][E.x][E.o] > E.hp) continue; Cost[E.y][E.x][E.o] = E.hp; REP(k, 0, 4) { int nx = E.x + dx[k]; int ny = E.y + dy[k]; int no = E.o; if (L[ny][nx] == -1) continue; int nc = E.hp - L[ny][nx]; if (ny == Oy && nx == Ox && !no) { nc *= 2; no = 1; } if (nc <= 0) continue; if (Cost[ny][nx][no] < nc) { Cost[ny][nx][no] = nc; pq.emplace(nx, ny, nc, no); } } } cout << (((Cost[N][N][0] > 0) || (Cost[N][N][1] > 0)) ? "YES" : "NO") << endl; return 0; }