結果

問題 No.1638 Robot Maze
ユーザー rianoriano
提出日時 2021-08-06 21:38:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,198 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 185,672 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-17 02:55:26
合計ジャッジ時間 3,436 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 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 3 ms
4,348 KB
testcase_14 AC 3 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 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 2 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 3 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 4 ms
4,372 KB
testcase_36 AC 4 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 4 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 4 ms
4,348 KB
testcase_43 AC 4 ms
4,348 KB
testcase_44 AC 4 ms
4,348 KB
testcase_45 AC 4 ms
4,348 KB
testcase_46 AC 4 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 4 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 4 ms
4,348 KB
testcase_51 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:63:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   63 |         auto[c,x,y] = p;
      |             ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;
#define double long double

const ll mod = 1000000007;


//dfs
//s:始点 i:dfs回数 t:始点からの距離
vector<int> vis; int t;
vector<int> depth;
//探索範囲を距離L以下に制限する場合
int L;
vector<ll> cnt(100001,0);
void dfs(Graph &G, int s,int i){
    int ti = t;
    t++;
    for(int nx:G[s]){
        if(t>=L) break;
        if(vis[nx]==i) continue;
        depth[nx] = depth[s] + 1;
        vis[nx] = i;
        dfs(G,nx,i);
    }
    t++;
    cnt[s] = (t-ti)/2;
}
    

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll H,W; cin >> H >> W;
    ll U,D,R,L,K,P; cin >> U >> D >> R >> L >> K >> P;
    ll cost[H][W];
    rep(i,H){
        rep(j,W) cost[i][j] = 2e18;
    }
    ll xs,xt,ys,yt; cin >> xs >> ys >> xt >> yt;
    cost[xs-1][ys-1] = 0;
    char g[H][W];
    rep(i,H){
        rep(j,W) cin >> g[i][j];
    }
    //Dijkstra (普通のダイクストラ)
    priority_queue<Tp, vector<Tp>, greater<Tp>> go;
    ll inf = 2e18;
    go.push(make_tuple(0,xs-1,ys-1)); 
    Tp p;
    vector<pair<int,int>> step;
    step.push_back(make_pair(-1,0));
    step.push_back(make_pair(0,-1));
    step.push_back(make_pair(1,0));
    step.push_back(make_pair(0,1));
    vector<ll> cs = {U,L,D,R};
    while(!go.empty()){
        p = go.top(); go.pop();
        auto[c,x,y] = p;
        if(c>cost[x][y]) continue;
        rep(i,4){
            ll z = x+step[i].first;
            ll w = y+step[i].second;
            if(0>z||z>=H||0>w||W<=w) continue;
            if(g[z][w]=='#') continue;
            ll cc = cost[x][y];
            if(g[z][w]=='@') cc += P;
            if(cc+cs[i]<cost[z][w]){
                cost[z][w] = cc+cs[i];
                go.push(make_tuple(cost[z][w],z,w));
                // cout << z << " " << w << endl;
                // cout << cost[z][w] << endl;
            }
        }
    }
    //cout << cost[xt-1][yt-1] << endl;
    string ans = "Yes";
    if(cost[xt-1][yt-1]>K) ans = "No";
    cout << ans << endl;
}
0