結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2021-08-06 22:31:42 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 2,619 bytes |
| コンパイル時間 | 3,503 ms |
| コンパイル使用メモリ | 268,648 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 02:35:21 |
| 合計ジャッジ時間 | 4,948 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
#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;
}
};
template<typename F>
struct Grid{
const int h,w;
const F f;
Grid(int h_,int w_,F f_):h(h_),w(w_),f(f_){}
int idx(int y,int x){return y*w+x;}
using T = typename invoke_result<F, int, int>::type;
T operator[](int k){return f(k/w,k%w);}
decltype(auto) edges(){
vector<pair<int, int>> es;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(i+1<h) es.emplace_back(idx(i,j),idx(i+1,j));
if(j+1<w) es.emplace_back(idx(i,j),idx(i,j+1));
}
}
return es;
}
};
//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 C=read<string>(h);
map<int, int> cost;
cost[-w]=u;
cost[+w]=d;
cost[+1]=r;
cost[-1]=l;
Grid G(h,w,[&](int y,int x){return C[y][x];});
Dijkstra<Int> D(h*w);
for(auto[a,b]:G.edges()){
if(G[a]=='#' or G[b]=='#') continue;
D.add_edge(a,b,cost[b-a]+p*(G[b]=='@'));
D.add_edge(b,a,cost[a-b]+p*(G[a]=='@'));
}
D.build(G.idx(ys,xs));
cout<<(D[G.idx(yt,xt)]<=k?"Yes":"No")<<newl;
return 0;
}
beet