// yukicoder: No.20 砂漠のオアシス // 2019.4.10 bal4u // 深さ優先探索 dfs #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { int n = 0, c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } typedef struct { int r, c, v; } Q; Q q[2000000]; int top; int N, V, OR, OC; int map[205][205]; int val[205][205]; int mv[4][2] = { {-1,0},{0,1},{1,0},{0,-1} }; int dfs(int sr, int sc, int gr, int gc) { int i, r, c, v, rr, cc, vv; q[0].r = sr, q[0].c = sc, q[0].v = V, top = 1; while (top) { r = q[--top].r, c = q[top].c, v = q[top].v; if (r == gr && c == gc) return 1; if (val[r][c] >= v) continue; val[r][c] = v; for (i = 0; i < 4; i++) { rr = r + mv[i][0], cc = c + mv[i][1]; if (rr < 0 || rr >= N || cc < 0 || cc >= N) continue; if ((vv = v - map[rr][cc]) < 0) continue; if (rr == OR && cc == OC) vv <<= 1; if (val[rr][cc] < vv) q[top].r = rr, q[top].c = cc, q[top++].v = vv; } } return 0; } int main() { int r, c; N = in(), V = in(), OR = in()-1, OC = in()-1; for (r = 0; r < N; r++) for (c = 0; c < N; c++) map[r][c] = in(); puts(dfs(0, 0, N - 1, N - 1) ? "YES" : "NO"); return 0; }