結果

問題 No.1638 Robot Maze
ユーザー ぷらぷら
提出日時 2021-08-06 21:37:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 3,994 ms
コンパイル使用メモリ 216,064 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 02:55:19
合計ジャッジ時間 3,910 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 4 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 4 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 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 4 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 4 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 5 ms
4,348 KB
testcase_33 AC 5 ms
4,348 KB
testcase_34 AC 5 ms
4,348 KB
testcase_35 AC 5 ms
4,348 KB
testcase_36 AC 5 ms
4,348 KB
testcase_37 AC 5 ms
4,348 KB
testcase_38 AC 4 ms
4,348 KB
testcase_39 AC 5 ms
4,348 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 5 ms
4,348 KB
testcase_42 AC 5 ms
4,348 KB
testcase_43 AC 6 ms
4,348 KB
testcase_44 AC 5 ms
4,348 KB
testcase_45 AC 5 ms
4,348 KB
testcase_46 AC 5 ms
4,348 KB
testcase_47 AC 5 ms
4,348 KB
testcase_48 AC 5 ms
4,348 KB
testcase_49 AC 5 ms
4,348 KB
testcase_50 AC 5 ms
4,348 KB
testcase_51 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

bool chmin(long long &x,long long y) {
    if(x > y) {
        x = y;
        return true;
    }
    return false;
}

int main() {
    int H,W;
    cin >> H >> W >> dz[0] >> dz[1] >> dz[2] >> dz[3];
    long long K;
    int P;
    cin >> K >> P;
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    vector<vector<pair<int,int>>>road(H*W);
    vector<string>S(H);
    for(int i = 0; i < H; i++) {
        cin >> S[i];
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            for(int k = 0; k < 4; k++) {
                int nx = i+dx[k];
                int ny = j+dy[k];
                if(nx >= 0 && nx < H && ny >= 0 && ny < W) {
                    if(S[nx][ny] == '#') {
                        continue;
                    }
                    if(S[nx][ny] == '@') {
                        road[i*W+j].push_back({nx*W+ny,P+dz[k]});
                    }
                    else {
                        road[i*W+j].push_back({nx*W+ny,dz[k]});
                    }
                }
            }
        }
    }
    vector<long long>dist(H*W,1001001001001001001);
    dist[a*W+b] = 0;
    priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>que;
    que.push({0,a*W+b});
    while (!que.empty()) {
        pair<long long,int>x = que.top();
        que.pop();
        if(dist[x.second] != x.first) {
            continue;
        }
        for(int i = 0; i < road[x.second].size(); i++) {
            if(chmin(dist[road[x.second][i].first],road[x.second][i].second+x.first)) {
                que.push({dist[road[x.second][i].first],road[x.second][i].first});
            }
        }
    }
    if(dist[c*W+d] <= K) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
0