結果

問題 No.1638 Robot Maze
ユーザー jutamajutama
提出日時 2021-08-07 18:50:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 11,208 bytes
コンパイル時間 4,100 ms
コンパイル使用メモリ 196,228 KB
実行使用メモリ 4,592 KB
最終ジャッジ日時 2023-10-18 23:38:50
合計ジャッジ時間 5,970 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 5 ms
4,592 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 5 ms
4,348 KB
testcase_33 AC 6 ms
4,372 KB
testcase_34 AC 6 ms
4,480 KB
testcase_35 AC 6 ms
4,372 KB
testcase_36 AC 6 ms
4,488 KB
testcase_37 AC 5 ms
4,348 KB
testcase_38 AC 5 ms
4,348 KB
testcase_39 AC 5 ms
4,464 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 5 ms
4,384 KB
testcase_42 AC 6 ms
4,380 KB
testcase_43 AC 5 ms
4,384 KB
testcase_44 AC 5 ms
4,404 KB
testcase_45 AC 6 ms
4,388 KB
testcase_46 AC 5 ms
4,444 KB
testcase_47 AC 5 ms
4,364 KB
testcase_48 AC 5 ms
4,480 KB
testcase_49 AC 5 ms
4,348 KB
testcase_50 AC 5 ms
4,388 KB
testcase_51 AC 6 ms
4,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bitset>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<int, ll> pil;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, ld> pid;
typedef std::pair<int, std::string> pis;
typedef std::pair<ll, std::string> pls;
typedef std::vector<bool> vb;
typedef std::vector<vb> vvb;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<vvi> vvvi;
typedef std::vector<vvvi> vvvvi;
typedef std::vector<ll> vl;
typedef std::vector<vl> vvl;
typedef std::vector<vvl> vvvl;
typedef std::vector<vvvl> vvvvl;
typedef std::vector<ld> vd;
typedef std::vector<vd> vvd;
typedef std::vector<std::string> vs;
#define rep(i,n) for(auto i=0; i<n; ++i)
#define repm(i,s,n) for(auto i=s; i<n; ++i)
#define repd(i,n) for(auto i=n-1; 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 <class T> inline bool chmax(T& a, T b, int eq = 0) { if (a < b || (a == b && eq)) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b, int eq = 0) { if (a > b || (a == b && eq)) { a = b; return 1; } return 0; }

template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr istream& operator>>(istream& is, mint& x) noexcept {long long v = 0; std::cin >> v; x = v; return is;}
template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr ostream& operator<<(ostream& os, const mint& x) noexcept {os << x.val(); return os;}
inline void _n() { std::cout << std::endl; }
template <class T> inline void _(const T a) { std::cout << a; }
template <class T> inline void _l(const T a) { _(a); _n(); }
template <class T> inline void _s(const T a) { _(a); _(' '); }
template <class T> inline void _v(const std::vector<T> v) { for(auto a : v) _(a); }
template <class T> inline void _vl(const std::vector<T> v) { for(auto a : v) _l(a); }
template <class T> inline void _vs(const std::vector<T> v) { for(auto a : v) _s(a); _n(); }
template <class T> inline void _vvl(const std::vector<std::vector<T>> v) { for(auto a : v) { _v(a); _n(); } }
template <class T> inline void _vvs(const std::vector<std::vector<T>> 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<int>::max() >> 1;
constexpr long long INF_LL = numeric_limits<long long>::max() >> 1LL;
constexpr long long MOD1 = 1000000007;
constexpr long long MOD9 = 998244353;
using mint1 = atcoder::modint1000000007;
using mint9 = atcoder::modint998244353;

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

template <class Cost> 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<int> get_edges(int v) {
        std::vector<int> 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<int> get_articulation_points(int s = 0) {
        if(s > 0) std::sort(_aps.begin(), _aps.end());
        return _aps;
    }
    std::vector<std::pair<int, int>> 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<bool(_edge, _edge)>> 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<int>(_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<Cost>::max();

    struct _edge {
        unsigned int from;
        unsigned int to;
        Cost cost;
    };
    std::vector<std::vector<_edge>> _graph;
    std::vector<Cost> _dist;

    std::vector<int> _depth;
    std::vector<std::vector<int>> _parent;

    std::vector<int> _used, _ord, _low;
    std::vector<int> _aps;
    std::vector<std::pair<int, int>> _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<ll> 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;
}
0