結果

問題 No.1638 Robot Maze
ユーザー kimiyukikimiyuki
提出日時 2021-08-06 21:43:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 2,315 ms
コンパイル使用メモリ 217,040 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 03:01:32
合計ジャッジ時間 3,771 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 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 3 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 3 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 4 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 4 ms
4,348 KB
testcase_42 AC 4 ms
4,348 KB
testcase_43 AC 4 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 4 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 4 ms
4,348 KB
testcase_50 AC 4 ms
4,348 KB
testcase_51 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

// generated by oj-template v4.8.0 (https://github.com/online-judge-tools/template-generator)
const std::string YES = "Yes";
const std::string NO = "No";
int main() {
    // input
    int h, w, up, down, left, right;
    int64_t k, p;
    cin >> h >> w >> up >> down >> right >> left >> k >> p;
    int sx, sy, tx, ty;
    cin >> sy >> sx >> ty >> tx;
    -- sx;
    -- sy;
    -- tx;
    -- ty;
    vector<string> c(h);
    REP (y, h) { cin >> c[y]; }

    // solve
    vector<vector<int64_t>> dist(h, vector<int64_t>(w, INT64_MAX));
    reversed_priority_queue<tuple<int64_t, int, int>> que;
    dist[sy][sx] = 0;
    que.emplace(0, sy, sx);
    while (not que.empty()) {
        auto [dist_y_x, y, x] = que.top();
        que.pop();
        if (dist_y_x > dist[y][x]) {
            continue;
        }
        REP (i, 4) {
            const int dy[4] = {-1, 1, 0, 0};
            const int dx[4] = {0, 0, 1, -1};
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (0 <= ny and ny < h and 0 <= nx and nx < w) {
                if (c[ny][nx] == '#') {
                    continue;
                }
                const int cost[4] = {up, down, right, left};
                int64_t ndist = dist[y][x] + cost[i] + (c[ny][nx] == '@' ? p : 0);
                if (ndist < dist[ny][nx]) {
                    dist[ny][nx] = ndist;
                    que.emplace(ndist, ny, nx);
                }
            }
        }
    }
    bool ans = dist[ty][tx] <= k;

    // output
    cout << (ans ? YES : NO) << '\n';
    return 0;
}
0