結果

問題 No.1638 Robot Maze
ユーザー sotanishysotanishy
提出日時 2021-08-06 21:42:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 1,690 bytes
コンパイル時間 2,823 ms
コンパイル使用メモリ 224,288 KB
実行使用メモリ 20,304 KB
最終ジャッジ日時 2023-10-17 02:59:47
合計ジャッジ時間 13,837 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 313 ms
19,524 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 197 ms
19,524 KB
testcase_15 AC 85 ms
19,524 KB
testcase_16 AC 85 ms
19,524 KB
testcase_17 AC 84 ms
19,524 KB
testcase_18 AC 15 ms
19,524 KB
testcase_19 AC 45 ms
19,612 KB
testcase_20 AC 46 ms
19,612 KB
testcase_21 AC 17 ms
19,524 KB
testcase_22 AC 15 ms
19,524 KB
testcase_23 AC 86 ms
19,524 KB
testcase_24 AC 18 ms
19,524 KB
testcase_25 AC 17 ms
19,524 KB
testcase_26 AC 99 ms
19,524 KB
testcase_27 AC 99 ms
19,524 KB
testcase_28 AC 95 ms
19,524 KB
testcase_29 AC 95 ms
19,524 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 282 ms
19,524 KB
testcase_33 AC 373 ms
19,612 KB
testcase_34 AC 406 ms
19,684 KB
testcase_35 AC 349 ms
19,524 KB
testcase_36 AC 431 ms
19,684 KB
testcase_37 AC 281 ms
19,524 KB
testcase_38 AC 402 ms
19,632 KB
testcase_39 AC 580 ms
19,944 KB
testcase_40 AC 361 ms
19,524 KB
testcase_41 AC 422 ms
19,628 KB
testcase_42 AC 429 ms
19,640 KB
testcase_43 AC 583 ms
19,944 KB
testcase_44 AC 532 ms
20,304 KB
testcase_45 AC 510 ms
19,944 KB
testcase_46 AC 514 ms
19,944 KB
testcase_47 AC 445 ms
19,944 KB
testcase_48 AC 435 ms
19,684 KB
testcase_49 AC 363 ms
19,524 KB
testcase_50 AC 436 ms
19,640 KB
testcase_51 AC 478 ms
19,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    const ll INF = 1e18;
    int H, W;
    cin >> H >> W;
    int U, D, R, L, P;
    ll K;
    cin >> U >> D >> R >> L >> K >> P;
    int xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    --xs, --ys, --xt, --yt;
    vector<string> C(H);
    for (auto& x : C) cin >> x;
    vector dist(H, vector<vector<ll>>(W, vector<ll>(H+W, INF)));
    dist[xs][ys][0] = 0;

    vector<int> dx = {-1, 1, 0, 0};
    vector<int> dy = {0, 0, 1, -1};
    vector<int> cost = {U, D, R, L};

    using T = tuple<ll, int, int, int>;
    priority_queue<T, vector<T>, greater<T>> pq;
    pq.push({0, xs, ys, 0});
    while (!pq.empty()) {
        ll d;
        int x, y, t;
        tie(d, x, y, t) = pq.top();
        pq.pop();
        if (dist[x][y][t] < d) continue;
        for (int k = 0; k < 4; ++k) {
            int nx = x + dx[k], ny = y + dy[k];
            if (0 <= nx && nx < H && 0 <= ny && ny <= W && C[nx][ny] != '#') {
                if (C[nx][ny] == '.' && dist[nx][ny][t] > d + cost[k]) {
                    dist[nx][ny][t] = d + cost[k];
                    pq.push({dist[nx][ny][t], nx, ny, t});
                }
                if (C[nx][ny] == '@' && t+1 < H+W && dist[nx][ny][t+1] > d + cost[k] + P) {
                    dist[nx][ny][t+1] = d + cost[k] + P;
                    pq.push({dist[nx][ny][t+1], nx, ny, t+1});
                }
            }
        }
    }
    for (int t = 0; t < H + W; ++t) {
        if (dist[xt][yt][t] <= K) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
0