#include #include using namespace std; using namespace atcoder; #define ll long long #define ull unsigned long long #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, n) for(int i = n; i >= 0; i--) #define rrep2(i, a, b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define eb emplace_back #define fi first #define se second #define sz(x) (int)x.size() #define pii pair #define pll pair #define endl '\n' template using pq = priority_queue< T >; template using pqg = priority_queue< T , vector< T >, greater< T >>; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = 1e9 + 1; const ll INF = 1e18 + 1; const int MOD = 1000000007; const double PI = 3.1415926535; bool range(int y, int x, int h, int w){ return (0 <= y && y < h && 0 <= x && x < w); } int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int main(){ cout << fixed << setprecision(15); int h, w; cin >> h >> w; ll u, d, r, l, k, p; cin >> u >> d >> r >> l >> k >> p; vector dir = {2*r, 2*d, 2*l, 2*u}; int sy, sx, gy, gx; cin >> sy >> sx >> gy >> gx; sy--; sx--; gy--; gx--; char c[h][w]; rep(i, h)rep(j, w) cin >> c[i][j]; vector> G(h*w); rep(i, h)rep(j, w){ if(c[i][j] == '#') continue; if(c[i][j] == '.'){ rep(d, 4){ int ni = i + dy[d]; int nj = j + dx[d]; ll cost = 0; if(!range(ni, nj, h, w)) continue; if(c[ni][nj] == '#') continue; if(c[ni][nj] == '@') cost += p; cost += dir[d]; G[i*w+j].eb(ni*w+nj, cost); } } if(c[i][j] == '@'){ rep(d, 4){ int ni = i + dy[d]; int nj = j + dx[d]; ll cost = p; if(!range(ni, nj, h, w)) continue; if(c[ni][nj] == '#') continue; if(c[ni][nj] == '@') cost += p; cost += dir[d]; G[i*w+j].eb(ni*w+nj, cost); } } } pqg> que; que.push(make_tuple(0, sy, sx)); vector dist(h, vector(w, INF)); dist[sy][sx] = 0; while(!que.empty()){ auto[cost, y, x] = que.top(); que.pop(); if(dist[y][x] < cost) continue; for(auto[pos, add] : G[y*w+x]){ int ny = pos/w; int nx = pos%w; if(dist[ny][nx] > cost + add){ dist[ny][nx] = cost + add; que.push(make_tuple(dist[ny][nx], ny, nx)); } } } if(dist[gy][gx]/2 <= k) cout << "Yes" << endl; else cout << "No" << endl; return 0; }