#include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; 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; } using namespace std; typedef long long ll; char c[100][100]; int h, w; int dh[4] = {-1, 1, 0, 0}; int dw[4] = {0, 0, 1, -1}; bool is_in_field(int i, int j){ return i >= 0 && i < h && j >= 0 && j < w; } const ll INF = 1e18; using T = tuple; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> h >> w; vector cost(4); ll k, p; for(int i = 0; i < 4; i++) cin >> cost[i]; cin >> k >> p; int xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt; xs--; ys--; xt--; yt--; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cin >> c[i][j]; } } vector> dist(h, vector(w, INF)); priority_queue, greater> que; auto add = [&](ll d, int x, int y){ if(d < dist[x][y]){ dist[x][y] = d; que.push(T(d, x, y)); } }; add(0, xs, ys); while(!que.empty()){ auto [d, x, y] = que.top(); que.pop(); // cout << x << ' ' << y << ' ' << d << endl; for(int i = 0; i < 4; i++){ int x_to = x+dh[i]; int y_to = y+dw[i]; if(!is_in_field(x_to, y_to)) continue; if(c[x_to][y_to] == '#') continue; ll nx_dist = d+cost[i]; if(c[x_to][y_to] == '@') nx_dist += p; add(nx_dist, x_to, y_to); } } if(dist[xt][yt] <= k) cout << "Yes" << endl; else cout << "No" << endl; }