結果

問題 No.1638 Robot Maze
ユーザー rogi52rogi52
提出日時 2022-10-17 03:20:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,549 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 213,472 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 04:34:17
合計ジャッジ時間 5,504 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

// g <- pair < v , cost > 
template < class T >
vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, int s) {
    T INF = numeric_limits< T >::max();
    vector<T> dist(graph.size(), INF);
    priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
    q.push({dist[s] = T(0), s});
    while(!q.empty()){
        auto [uc, ui] = q.top(); q.pop();
        if(uc != dist[ui]) continue;
        for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) 
            q.push({dist[vi] = uc + vc, vi});
    }
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll H,W,U,D,R,L,K,P; cin >> H >> W >> U >> D >> R >> L >> K >> P;
    int xs,ys,xt,yt; cin >> xs >> ys >> xt >> yt; xs--, ys--, xt--, yt--;
    vector<string> C(H);
    rep(i,H) cin >> C[i];

    vector<vector<pair<int,ll>>> G(H * W);
    auto h = [&](int i, int j){ return i * W + j; };

    int di[] = {-1, +1, 0, 0};
    int dj[] = {0, 0, +1, -1};
    ll cost[] = {U, D, R, L};
    rep(i,H)rep(j,W)if(C[i][j] != '#')rep(d,4) {
        int ni = i + di[d], nj = j + dj[d];
        if(0 <= ni && ni < H && 0 <= nj && nj < W) {
            if(C[ni][nj] == '.') {
                G[h(i, j)].push_back({h(ni, nj), cost[d]});
            } else if(C[ni][nj] == '@') {
                G[h(i, j)].push_back({h(ni, nj), P});
            }
        }
    }

    cout << (dijkstra(G, h(xs, ys))[h(xt, yt)] <= K ? "Yes" : "No") << endl;
}
0