#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define inf 0x3f3f3f3f3f3f3f3f #define mp make_pair #define all(a) (a).begin(),(a).end() #define pii pair #define pcc pair #define pic pair #define pci pair #define VS vector #define VI vector #define DEBUG(x) cout<<#x<<": "<> H >> W; int A; cin >> A; point S; cin >> S.y >> S.x; int B; cin >> B; point G; cin >> G.y >> G.x; vector M(H); for (auto &a : M) cin >> a; int cut = max(A, B) + H + W;//これ以上行くパターンはウロウロしてるのでいらない queue> que; que.push(mp(A, point(S))); used[A][S.y][S.x] = true; while (not que.empty()) { auto t = que.front(); que.pop(); int x = t.second.x; int y = t.second.y; used[t.first][t.second.y][t.second.x] = true; if (used[B][G.y][G.x]) break; if (t.first <= 0 or t.first > cut) continue; REP(i, 4) { if (0 <= x + dx[i] and x + dx[i] < W and 0 <= y + dy[i] and y + dy[i] < H) { int score = t.first + (M[y + dy[i]][x + dx[i]] == '.' ? -1 : 1); if (not used[score][y + dy[i]][x + dx[i]]) que.push(mp(score, point(x + dx[i], y + dy[i]))); } } } cout << (used[B][G.y][G.x] ? "Yes" : "No") << endl;; return 0; }