結果

問題 No.1638 Robot Maze
ユーザー beetbeet
提出日時 2021-08-06 21:53:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 2,566 bytes
コンパイル時間 3,207 ms
コンパイル使用メモリ 259,348 KB
実行使用メモリ 4,548 KB
最終ジャッジ日時 2023-10-17 03:13:58
合計ジャッジ時間 4,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 5 ms
4,548 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,368 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 4 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 4 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,440 KB
testcase_33 AC 5 ms
4,492 KB
testcase_34 AC 5 ms
4,528 KB
testcase_35 AC 5 ms
4,504 KB
testcase_36 AC 5 ms
4,528 KB
testcase_37 AC 4 ms
4,444 KB
testcase_38 AC 5 ms
4,440 KB
testcase_39 AC 5 ms
4,544 KB
testcase_40 AC 5 ms
4,456 KB
testcase_41 AC 5 ms
4,496 KB
testcase_42 AC 5 ms
4,500 KB
testcase_43 AC 5 ms
4,488 KB
testcase_44 AC 5 ms
4,496 KB
testcase_45 AC 5 ms
4,488 KB
testcase_46 AC 5 ms
4,512 KB
testcase_47 AC 5 ms
4,476 KB
testcase_48 AC 5 ms
4,528 KB
testcase_49 AC 5 ms
4,444 KB
testcase_50 AC 5 ms
4,492 KB
testcase_51 AC 5 ms
4,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}



template<typename T>
struct Dijkstra{
  struct Edge{
    Int to;
    T cost;
    Edge(Int to,T cost):to(to),cost(cost){}
    bool operator<(const Edge &o)const{return cost>o.cost;}
  };

  vector< vector<Edge> > G;
  vector<T> ds;
  vector<Int> bs;
  Dijkstra(Int n):G(n){}

  void add_edge(Int u,Int v,T c){
    G[u].emplace_back(v,c);
  }

  void build(Int s){
    Int n=G.size();
    ds.assign(n,numeric_limits<T>::max());
    bs.assign(n,-1);

    priority_queue<Edge> pq;
    ds[s]=0;
    pq.emplace(s,ds[s]);

    while(!pq.empty()){
      auto p=pq.top();pq.pop();
      Int v=p.to;
      if(ds[v]<p.cost) continue;
      for(auto e:G[v]){
        if(ds[e.to]>ds[v]+e.cost){
          ds[e.to]=ds[v]+e.cost;
          bs[e.to]=v;
          pq.emplace(e.to,ds[e.to]);
        }
      }
    }
  }

  T operator[](Int k){return ds[k];}

  vector<Int> restore(Int to){
    vector<Int> res;
    if(bs[to]<0) return res;
    while(~to) res.emplace_back(to),to=bs[to];
    reverse(res.begin(),res.end());
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int h,w;
  cin>>h>>w;
  Int u,d,r,l,k,p;
  cin>>u>>d>>r>>l>>k>>p;
  Int ys,xs,yt,xt;
  cin>>ys>>xs>>yt>>xt;
  ys--;xs--;yt--;xt--;
  auto idx=[&](Int y,Int x){return y*w+x;};

  auto C=read<string>(h);

  Dijkstra<Int> G(h*w);
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      if(i-1>=0){
        Int ni=i-1,nj=j+0;
        Int c=u+p*(C[ni][nj]=='@');
        if(C[ni][nj]!='#')
          G.add_edge(idx(i,j),idx(ni,nj),c);
      }
      if(i+1<h){
        Int ni=i+1,nj=j+0;
        Int c=d+p*(C[ni][nj]=='@');
        if(C[ni][nj]!='#')
          G.add_edge(idx(i,j),idx(ni,nj),c);
      }
      if(j+1<w){
        Int ni=i-0,nj=j+1;
        Int c=r+p*(C[ni][nj]=='@');
        if(C[ni][nj]!='#')
          G.add_edge(idx(i,j),idx(ni,nj),c);

      }
      if(j-1>=0){
        Int ni=i-0,nj=j-1;
        Int c=l+p*(C[ni][nj]=='@');
        if(C[ni][nj]!='#')
          G.add_edge(idx(i,j),idx(ni,nj),c);
      }
    }
  }


  G.build(idx(ys,xs));
  cout<<(G[idx(yt,xt)]<=k?"Yes":"No")<<newl;
  return 0;
}
0