結果

問題 No.1638 Robot Maze
ユーザー abc3abc3
提出日時 2021-08-06 23:31:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 2,314 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 215,316 KB
実行使用メモリ 5,188 KB
最終ジャッジ日時 2023-10-17 05:25:15
合計ジャッジ時間 5,172 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 6 ms
5,188 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 5 ms
4,376 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 4 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 4 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 4 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,640 KB
testcase_33 AC 6 ms
4,676 KB
testcase_34 AC 6 ms
4,920 KB
testcase_35 AC 6 ms
4,660 KB
testcase_36 AC 6 ms
4,936 KB
testcase_37 AC 6 ms
4,640 KB
testcase_38 AC 5 ms
4,640 KB
testcase_39 AC 6 ms
4,904 KB
testcase_40 AC 6 ms
4,640 KB
testcase_41 AC 6 ms
4,696 KB
testcase_42 AC 6 ms
4,852 KB
testcase_43 AC 6 ms
4,852 KB
testcase_44 AC 6 ms
4,764 KB
testcase_45 AC 6 ms
4,736 KB
testcase_46 AC 6 ms
4,904 KB
testcase_47 AC 6 ms
4,688 KB
testcase_48 AC 6 ms
4,924 KB
testcase_49 AC 6 ms
4,640 KB
testcase_50 AC 7 ms
4,724 KB
testcase_51 AC 7 ms
4,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

   #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    const ll INF=1e18;
    const int mod=998244353;
    
    struct edge{
      int to;
      ll w;
      edge(int to,ll w):to(to),w(w){}
    };
    using Graph=vector<vector<edge>>;
    
    int n;
    ll h,w,k,p,xs,ys,xt,yt;
    
    int toid(int i,int j){return i*w+j;}
    
    ll dijkstra(int s,Graph G){
      vector<ll> dist(n,INF);
      dist[s]=0;
      priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>q;
      q.push({dist[s],s});
      while(!q.empty()){
        int v=q.top().second;
        ll d=q.top().first;
        q.pop();
        if(d>dist[v]){continue;}
        for(auto e:G[v]){
          if(chmin(dist[e.to],dist[v]+e.w)){
            q.push({dist[e.to],e.to});
          }
        }
      }
      return dist[toid(yt,xt)];
    }

    char c[105][105];
    int dx[4]={0,0,1,-1},dy[4]={-1,1,0,0};

    void solve(){
        cin>>h>>w;
        vector<ll>s(4);
        rep(i,4){cin>>s[i];}
        
        cin>>k>>p>>ys>>xs>>yt>>xt;
        xs--;ys--;xt--;yt--;

        n=h*w;
        Graph G(n);

        rep(i,h){
            rep(j,w){
                cin>>c[i][j];
            }
        }
        
        rep(i,h){
            rep(j,w){
                if(c[i][j]=='#'){continue;}
                rep(k,4){
                    int ni=i+dy[k],nj=j+dx[k];
                    if(ni>=0&&ni<h&&nj>=0&&nj<w&&c[ni][nj]!='#'){
                        ll cost=s[k]+(c[ni][nj]=='@'?p:0);
                        G[toid(i,j)].push_back(edge(toid(ni,nj),cost));
                    }
                }
            }
        }
        ll dist=dijkstra(toid(ys,xs),G);
        if(dist<=k){cout<<"Yes"<<endl;}
        else{cout<<"No"<<endl;}
    }

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve();  

        return 0;
    }
0