結果

問題 No.1638 Robot Maze
ユーザー ktr216
提出日時 2021-08-06 21:56:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,200 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 182,340 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-17 01:54:10
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;

typedef long long ll;

int main() {
    int H, W, xs, ys, xt, yt, dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, 1, -1};
    vector<int> cost(4);
    ll K, P;
    cin >> H >> W;
    rep(i, 0, 4) cin >> cost[i];
    cin >> K >> P >> xs >> ys >> xt >> yt;
    xs--;
    ys--;
    xt--;
    yt--;
    vector<string> C(H);
    rep(i, 0, H) cin >> C[i];
    vector<vector<ll>> A(H, vector<ll>(W, 1e18));
    priority_queue<vector<ll>> q;
    A[xs][ys] = 0;
    q.push({0, xs, ys});
    while (!q.empty()) {
        auto r = q.top();
        q.pop();
        ll d = -r[0], x = r[1], y = r[2];
        //cout << "d=" << d << " x=" << x << " y=" << y << endl;
        rep(i, 0, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (C[nx][ny] == '#') continue;
            ll nd = d + cost[i];
            if (C[nx][ny] == '@') nd += P;
            if (nd >= A[nx][ny]) continue;
            A[nx][ny] = nd;
            q.push({-nd, nx, ny});
        }
    }
    if (A[xt][yt] > K) cout << "No" << endl;
    else cout << "Yes" << endl;
}
0