// clang-format off #include #include #include #define mp make_pair #define fst first #define snd second #define forn(i,n) for (int i = 0; i < int(n); i++) #define forn1(i,n) for (int i = 1; i <= int(n); i++) #define popcnt __builtin_popcountll #define ffs __builtin_ffsll #define ctz __builtin_ctzll #define clz __builtin_clz #define clzll __builtin_clzll #define all(a) (a).begin(), (a).end() using namespace std; using namespace __gnu_pbds; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair; using pli = pair; using pil = pair; using pll = pair; template using vec = vector; using vi = vec; using vl = vec; template using que = queue; template using deq = deque; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; template T id(T b) {return b;}; template void chmax(T &x, T y) {if (x < y) x = y;} template void chmin(T &x, T y) {if (x > y) x = y;} template bool contains(S &s, K k) { return s.find(k) != s.end(); } template bool getf(T flag, size_t i) { return (flag>>i) & 1; } template T setf(T flag, size_t i) { return flag | (T(1)< T unsetf(T flag, size_t i) { return flag & ~(T(1)<> h >> w >> u >> d >> r >> l >> k >> p; int xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt; xs--, ys--, xt--, yt--; vec grid(h); forn(i, h) cin >> grid[i]; const ll INF = TEN(16); auto idx = [&](int i, int j) { return i * w + j; }; const int n = h * w; vi di = { -1, 0, 1, 0 }; vi dj = { 0, 1, 0, -1 }; auto ok = [&](int i, int j) { return 0 <= i and i < h and 0 <= j and j < w and grid[i][j] != '#'; }; vi cost = { u, r, d, l }; vec> g(n); forn(i, h) { forn(j, w) { forn(k, 4) { int newi = i + di[k]; int newj = j + dj[k]; if (ok(newi, newj)) { int c = cost[k]; if (grid[newi][newj] == '@') c += p; g[idx(i, j)].emplace_back(idx(newi, newj), c); } } } } priority_queue, greater> q; q.emplace(0, idx(xs, ys)); vl dist(n, INF); while (!q.empty()) { auto [c, u] = q.top(); q.pop(); if (dist[u] < c) continue; for (auto [v, ec] : g[u]) { if (c + ec >= dist[v]) continue; dist[v] = c + ec; q.emplace(dist[v], v); } } cout << (dist[idx(xt, yt)] <= k ? "Yes" : "No") << endl; return 0; }