/* -*- coding: utf-8 -*- * * 1949.cc: No.1949 足し算するだけのパズルゲーム(2) - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_H = 500; const int MAX_W = 500; const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 }; /* typedef */ typedef long long ll; struct Elm { int a, y, x; Elm() {} Elm(int _a, int _y, int _x): a(_a), y(_y), x(_x) {} bool operator<(const Elm &e) const { return a > e.a; } }; /* global variables */ int as[MAX_H][MAX_W]; bool used[MAX_H][MAX_W]; /* subroutines */ /* main */ int main() { int h, w, sy, sx; scanf("%d%d%d%d", &h, &w, &sy, &sx); sy--, sx--; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", as[i] + j); used[sy][sx] = true; priority_queue q; q.push(Elm(as[sy][sx], sy, sx)); ll sum = 0; while (! q.empty()) { Elm e = q.top(); q.pop(); if (sum > 0 && sum <= e.a) { puts("No"); return 0; } sum += e.a; for (int di = 0; di < 4; di++) { int vy = e.y + dys[di], vx = e.x + dxs[di]; if (vy >= 0 && vy < h && vx >= 0 && vx < w && ! used[vy][vx]) { used[vy][vx] = true; q.push(Elm(as[vy][vx], vy, vx)); } } } puts("Yes"); return 0; }