module main; // https://kmjp.hatenablog.jp/entry/2015/12/17/0900 より // 2次元グリッド、幅優先探索 import std; struct State { int sz; // 雪玉の大きさ int x, y; } auto dirX = [1, -1, 0, 0]; auto dirY = [0, 0, 1, -1]; void main() { // 入力 int H, W; readln.chomp.formattedRead("%d %d", H, W); State S; readln.chomp.formattedRead("%d %d %d", S.sz, S.x, S.y); State G; readln.chomp.formattedRead("%d %d %d", G.sz, G.x, G.y); auto M = new string[](H); foreach (ref m; M) m = readln.chomp; // 答えの計算 auto visited = new bool[][][](H, W, 3500); visited[S.x][S.y][S.sz] = true; auto que = DList!State(S); while (!que.empty) { State cur = que.removeAny; foreach (dx, dy; lockstep(dirX, dirY)) { int nx = cur.x + dx, ny = cur.y + dy; if (nx < 0 || H <= nx || ny < 0 || W <= ny) continue; int nsz = cur.sz + (M[nx][ny] == '*' ? 1 : -1); if (nsz <= 0 || 3500 <= nsz) continue; if (visited[nx][ny][nsz]) continue; visited[nx][ny][nsz] = true; que.insertFront(State(nsz, nx, ny)); } } // 答えの出力 writeln(visited[G.x][G.y][G.sz] ? "Yes" : "No"); }