結果

問題 No.1638 Robot Maze
ユーザー umezo
提出日時 2021-08-06 22:17:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,887 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 204,792 KB
最終ジャッジ日時 2025-01-23 15:40:22
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

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