#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; typedef std::pair pii; typedef std::pair pil; typedef std::pair pli; typedef std::pair pll; typedef std::pair pid; typedef std::pair pis; typedef std::pair pls; typedef std::vector vb; typedef std::vector vvb; typedef std::vector vi; typedef std::vector vvi; typedef std::vector vvvi; typedef std::vector vvvvi; typedef std::vector vl; typedef std::vector vvl; typedef std::vector vvvl; typedef std::vector vvvvl; typedef std::vector vd; typedef std::vector vvd; typedef std::vector vs; #define rep(i,n) for(auto i=0; i=0; --i) #define repdm(i,e,n) for(auto i=n-1; i>=e; --i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() template inline bool chmax(T& a, T b, int eq = 0) { if (a < b || (a == b && eq)) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b, int eq = 0) { if (a > b || (a == b && eq)) { a = b; return 1; } return 0; } template * = nullptr> constexpr istream& operator>>(istream& is, mint& x) noexcept {long long v = 0; std::cin >> v; x = v; return is;} template * = nullptr> constexpr ostream& operator<<(ostream& os, const mint& x) noexcept {os << x.val(); return os;} inline void _n() { std::cout << std::endl; } template inline void _(const T a) { std::cout << a; } template inline void _l(const T a) { _(a); _n(); } template inline void _s(const T a) { _(a); _(' '); } template inline void _v(const std::vector v) { for(auto a : v) _(a); } template inline void _vl(const std::vector v) { for(auto a : v) _l(a); } template inline void _vs(const std::vector v) { for(auto a : v) _s(a); _n(); } template inline void _vvl(const std::vector> v) { for(auto a : v) { _v(a); _n(); } } template inline void _vvs(const std::vector> v) { for(auto a : v) { _vs(a); } } inline void ynl(const bool b) {_l(b ? "yes" : "no");} inline void yns(const bool b) {_l(b ? "Yes" : "No");} inline void ynu(const bool b) {_l(b ? "YES" : "NO");} constexpr int INF = numeric_limits::max() >> 1; constexpr long long INF_LL = numeric_limits::max() >> 1LL; constexpr long long MOD1 = 1000000007; constexpr long long MOD9 = 998244353; using mint1 = atcoder::modint1000000007; using mint9 = atcoder::modint998244353; //* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *// template struct graph_l { public : graph_l(int n) : _n(n), _graph(n), _dist(n, 0) {} void add (int from, int to, Cost cost){ assert(0 <= from && from < _n); assert(0 <= to && to < _n); _graph[from].push_back(_edge{(unsigned int)from, (unsigned int)to, cost}); } void add_bi (int from, int to, Cost cost){ add(from, to, cost); add(to, from, cost); } std::vector get_edges(int v) { std::vector edges; for (auto edge : _graph[v]) { edges.push_back(edge.to); } return edges; } bool is_Reachable (int v) { assert(0 <= v && v < _n); return _dist[v] < DIST_INF; } Cost get_dist (int v) { assert(0 <= v && v < _n); return _dist[v]; } int get_lca(int u, int v) { assert(0 <= u && u < _n); assert(0 <= v && v < _n); if (_depth[u] < _depth[v]) swap(u, v); int K = (int)_parent.size(); for (int k = 0; k < K; k++) { if ((_depth[u] - _depth[v]) >> k & 1) { u = _parent[k][u]; } } if (u == v) return u; for (int k = K - 1; k >= 0; k--) { if (_parent[k][u] != _parent[k][v]) { u = _parent[k][u]; v = _parent[k][v]; } } return _parent[0][u]; } Cost get_dist_with_lca (int u, int v) { assert(0 <= u && u < _n); assert(0 <= v && v < _n); return _dist[u] + _dist[v] - 2 * _dist[get_lca(u, v)]; } std::vector get_articulation_points(int s = 0) { if(s > 0) std::sort(_aps.begin(), _aps.end()); return _aps; } std::vector> get_bridges(int s = 0) { if(s > 0) std::sort(_bridges.begin(), _bridges.end()); return _bridges; } void dijkstra (int s) { assert(0 <= s && s < _n); _dist.assign(_n, DIST_INF); _dist[s] = 0; auto edge_compare = [] (_edge e1, _edge e2) { if (e1.cost != e2.cost) return e1.cost > e2.cost; else if (e1.to != e2.to) return e1.to > e2.to; else return e1.from > e2.from; }; priority_queue<_edge, vector<_edge>, function> edge_que(edge_compare); edge_que.push(_edge{(unsigned int)s, (unsigned int)s, 0}); // for (auto e : _graph[s]) { // edge_que.push(_edge{e.from, e.to, e.cost}); // if(_dist[e.to] > e.cost) _dist[e.to] = e.cost; // } while (!edge_que.empty()) { _edge p = edge_que.top(); edge_que.pop(); unsigned int v = p.to; if (_dist[v] < p.cost) continue; for (auto e : _graph[v]) { auto next_cost = e.cost + _dist[v]; if (_dist[e.to] <= next_cost) continue; _dist[e.to] = next_cost; edge_que.push(_edge{e.from, e.to, _dist[e.to]}); } } } bool bellman_ford (int s) { assert(0 <= s && s < _n); _dist.assign(_n, DIST_INF); _dist[s] = 0; for(int i = 0; i < _n - 1; ++i) { for(int j = 0; j < _n; ++j ){ for(auto e : _graph[j]) { if(_dist[j] == DIST_INF) continue; _dist[e.to] = min(_dist[e.to], _dist[j] + e.cost); } } } for(int j = 0; j < _n; ++j ){ for(auto e : _graph[j]) { if(_dist[j] == DIST_INF) continue; if(_dist[j] + e.cost < _dist[e.to]) return false; } } return true; } void lca(int r = 0) { assert(0 <= r && r < _n); int K = 1; while ((1 << K) < _n) K++; _dist.assign(_n, DIST_INF); _depth.assign(_n, -1); _parent.assign(K, std::vector(_n, -1)); dfs_lca(r, -1, 0, 0); for (int k = 0; k + 1 < K; k++) { for (int v = 0; v < _n; v++) { if (_parent[k][v] < 0) { _parent[k+1][v] = -1; } else { _parent[k+1][v] = _parent[k][_parent[k][v]]; } } } } Cost kruskal() { std::vector<_edge> edge_vec; for (int v = 0; v < _n; ++v) { for (auto e : _graph[v]) { edge_vec.push_back(e); } } auto edge_compare = [] (_edge e1, _edge e2) { if (e1.cost != e2.cost) return e1.cost < e2.cost; else if (e1.to != e2.to) return e1.to < e2.to; else return e1.from < e2.from; }; std::sort(edge_vec.begin(), edge_vec.end(), edge_compare); Cost _cost = 0; atcoder::dsu _dsu(_n); for (auto e : edge_vec) { if (!_dsu.same(e.from, e.to)) { _dsu.merge(e.from, e.to); _cost += e.cost; } } return _dsu.groups().size() == 1 ? _cost : -1; } void lowlink() { _used.resize(_n); _ord.resize(_n); _low.resize(_n); int j = 0; for (int i = 0; i < _n; i++) { if (!_used[i]) j = dfs_lowlink(i, j, -1); } } private: void dfs_lca(unsigned int v, int p, unsigned int d, Cost c) { _parent[0][v] = p; _depth[v] = d; _dist[v] = c; for (auto e : _graph[v]) { if (e.to != p) dfs_lca(e.to, v, d + 1, c + e.cost); } } int dfs_lowlink(unsigned int i, unsigned int j, int par) { _used[i] = true; _ord[i] = j++; _low[i] = _ord[i]; bool is_aps = false; int count = 0; for (auto e : _graph[i]) { if (!_used[e.to]) { count++; j = dfs_lowlink(e.to, j, i); _low[i] = min(_low[i], _low[e.to]); if (par != -1 && _ord[i] <= _low[e.to]) is_aps = true; if (_ord[i] < _low[e.to]) _bridges.emplace_back(min(i, e.to), max(i, e.to)); } else if (e.to != par) { _low[i] = min(_low[i], _ord[e.to]); } } if (par == -1 && count >= 2) is_aps = true; if (is_aps) _aps.push_back(i); return j; } private: int _n; const Cost DIST_INF = numeric_limits::max(); struct _edge { unsigned int from; unsigned int to; Cost cost; }; std::vector> _graph; std::vector _dist; std::vector _depth; std::vector> _parent; std::vector _used, _ord, _low; std::vector _aps; std::vector> _bridges; }; void solve() { int H, W; cin >> H >> W; vl D(4); rep(k, 4) cin >> D[k]; ll K, P; cin >> K >> P; int xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt; xs--; ys--; xt--; yt--; vs S(H); rep(i, H) cin >> S[i]; vi di = {-1, 1, 0, 0}; vi dj = {0, 0, 1, -1}; graph_l G(H*W); rep(i, H) rep(j, W) { if(S[i][j] == '#') continue; rep(k, 4) { int ni = i + di[k]; int nj = j + dj[k]; if(!(0 <= ni && ni < H && 0 <= nj && nj < W)) continue; if(S[ni][nj] == '#') continue; if(S[i][j] == '.' && S[ni][nj] == '.') G.add(i*W + j, ni*W + nj, 2 * D[k]); if(S[i][j] == '.' && S[ni][nj] == '@') G.add(i*W + j, ni*W + nj, 2 * D[k] + P); if(S[i][j] == '@' && S[ni][nj] == '.') G.add(i*W + j, ni*W + nj, 2 * D[k] + P); if(S[i][j] == '@' && S[ni][nj] == '@') G.add(i*W + j, ni*W + nj, 2 * D[k] + 2 * P); } } G.dijkstra(xs*W + ys); yns(G.get_dist(xt*W + yt) <= 2*K); } //* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *// int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); std::cin.tie(0); std::cout.tie(0); std::ios::sync_with_stdio(false); solve(); return 0; }