結果

問題 No.1638 Robot Maze
ユーザー umezoumezo
提出日時 2021-08-06 22:17:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,887 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 214,416 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-17 03:40:48
合計ジャッジ時間 4,037 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
4,476 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 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 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 4 ms
4,348 KB
testcase_33 AC 5 ms
4,348 KB
testcase_34 AC 5 ms
4,364 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 5 ms
4,400 KB
testcase_37 AC 4 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 5 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 4 ms
4,348 KB
testcase_48 AC 5 ms
4,368 KB
testcase_49 AC 4 ms
4,348 KB
testcase_50 AC 5 ms
4,348 KB
testcase_51 AC 5 ms
4,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

char C[110][110];

const ll INF=1LL<<60;

struct Edge{
  int to;
  ll w;
  Edge(int to,ll w) : to(to),w(w) {}
};

using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;

template<class T> bool chmin(T& a,T b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w;
  cin>>h>>w;
  
  ll u,d,r,l,k,P;
  cin>>u>>d>>r>>l>>k>>P;
  
  int xs,ys,xt,yt;
  cin>>xs>>ys>>xt>>yt;
  xs--,ys--,xt--,yt--;
  
  rep(i,h){
    rep(j,w) cin>>C[i][j];
  }
  
  Graph G(h*w);
  
  rep(i,h){
    rep(j,w){
      int p=i*w+j;
      int pu=p-w,pd=p+w,pr=p+1,pl=p-1;
      if(C[i][j]=='#') continue;
      else{
        if(i>0 && C[i-1][j]=='.') G[p].push_back(Edge(pu,u));
        else if(i>0 && C[i-1][j]=='@') G[p].push_back(Edge(pu,u+P));
        
        if(i<h-1 && C[i+1][j]=='.') G[p].push_back(Edge(pd,d));
        else if(i<h-1 && C[i+1][j]=='@') G[p].push_back(Edge(pd,d+P));
        
        if(j<w-1 && C[i][j+1]=='.') G[p].push_back(Edge(pr,r));
        else if(j<w-1 && C[i][j+1]=='@') G[p].push_back(Edge(pr,r+P));
                
        if(j>0 && C[i][j-1]=='.') G[p].push_back(Edge(pl,l));
        else if(j>0 && C[i][j-1]=='@') G[p].push_back(Edge(pl,l+P));
      }
    }
  }

  vector<ll> dist(h*w,INF);
  int s=xs*w+ys;
  dist[s]=0;
  
  priority_queue<pli,vector<pli>,greater<pli>> que;
  que.push({dist[s],s});
  
  while(!que.empty()){
    int v=que.top().second;
    ll d=que.top().first;
    que.pop();
    
    if(d>dist[v]) continue;
    
    for(auto e:G[v]){
      if(chmin(dist[e.to],dist[v]+e.w)){
        que.push({dist[e.to],e.to});
      }
    }
  }
  
  if(dist[xt*w+yt]<=k) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}
0