結果

問題 No.1638 Robot Maze
ユーザー kappybarkappybar
提出日時 2021-08-08 20:43:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 180,016 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 21:22:20
合計ジャッジ時間 4,679 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 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 34 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 21 ms
4,348 KB
testcase_33 AC 11 ms
4,348 KB
testcase_34 AC 204 ms
4,348 KB
testcase_35 AC 63 ms
4,348 KB
testcase_36 AC 15 ms
4,348 KB
testcase_37 AC 14 ms
4,348 KB
testcase_38 AC 6 ms
4,348 KB
testcase_39 AC 49 ms
4,348 KB
testcase_40 AC 125 ms
4,348 KB
testcase_41 AC 282 ms
4,348 KB
testcase_42 AC 50 ms
4,348 KB
testcase_43 AC 76 ms
4,348 KB
testcase_44 AC 51 ms
4,348 KB
testcase_45 AC 26 ms
4,348 KB
testcase_46 AC 12 ms
4,348 KB
testcase_47 AC 27 ms
4,348 KB
testcase_48 AC 131 ms
4,348 KB
testcase_49 AC 6 ms
4,348 KB
testcase_50 AC 271 ms
4,348 KB
testcase_51 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y))
#define chmax(x,y) x = max((x),(y))
#define popcount(x) __builtin_popcount(x)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};

int main(){
    int h,w;
    cin >> h >> w;
    vector<ll> cost(4);
    rep(i,4) cin >> cost[i];
    ll k,p;
    cin >> k >> p;

    int xs,ys,xt,yt;
    cin >> xs >> ys >> xt >> yt;
    --xs;--ys;--xt;--yt;

    vector<string> maze(h);
    rep(i,h) cin >> maze[i];

    vector<vector<ll>> dist(h,vector<ll>(w,LINF));
    auto id = [&](int i,int j){return i+j*h;};

    priority_queue<pll,vector<pll>,greater<pll>> pq;
    pq.push(pll{id(xs,ys),0});
    while(!pq.empty()){
        int x = pq.top().first % h;
        int y = pq.top().first / h;
        ll d = pq.top().second;
        pq.pop();
        if(dist[x][y] <= d) continue;
        dist[x][y] = d;

        rep(k,4){
            int new_x = x + dx[k];
            int new_y = y + dy[k];
            ll dis = d + cost[k];
            if(new_x < 0 || h <= new_x || new_y < 0 || w <= new_y) continue;
            if(maze[new_x][new_y] == '#') continue;
            if(maze[new_x][new_y] == '@') dis += p;

            pq.push(pll{id(new_x,new_y),dis});
        }
    }

    if(dist[xt][yt] <= k) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}
0