結果

問題 No.1638 Robot Maze
ユーザー sten_sansten_san
提出日時 2021-08-06 21:37:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,254 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 217,140 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 02:55:13
合計ジャッジ時間 4,063 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 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 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 4 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 4 ms
4,348 KB
testcase_46 AC 3 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 3 ms
4,348 KB
testcase_51 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

template <typename T>
using pqueue = priority_queue<T, vector<T>, greater<T>>;

int main() {
    constexpr int64_t inf = INT64_MAX / 2;

    constexpr int step[4][2] = {
        { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 },
    };

    int h, w; cin >> h >> w;
    int op[4] = {};
    for (auto &e : op) cin >> e;
    int64_t k, p; cin >> k >> p;

    int sy, sx; cin >> sy >> sx; --sy; --sx;
    int ty, tx; cin >> ty >> tx; --ty; --tx;

    auto f = vec<string>(uns, h);
    for (auto &e : f) cin >> e;

    pqueue<tuple<int64_t, int, int>> que;
    auto dist = vec<int64_t>(inf, h, w);

    que.push({ 0, sy, sx });
    dist[sy][sx] = 0;
    while (!empty(que)) {
        auto [c, y, x] = que.top(); que.pop();

        if (dist[y][x] < c) {
            continue;
        }

        for (int i = 0; i < 4; ++i) {
            auto [dy, dx] = step[i];

            int ny = y + dy;
            int nx = x + dx;

            if (min(ny, nx) < 0 || h <= ny || w <= nx) {
                continue;
            }

            if (f[ny][nx] == '#') {
                continue;
            }

            int64_t cost = op[i];
            if (f[ny][nx] == '@') {
                cost += p;
            }

            if (dist[ny][nx] <= c + cost) {
                continue;
            }
            dist[ny][nx] = c + cost;

            que.push({ c + cost, ny, nx });
        }
    }

    cout << (dist[ty][tx] <= k ? "Yes" : "No") << endl;
}

0