結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 21:31:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,463 bytes |
| コンパイル時間 | 2,865 ms |
| コンパイル使用メモリ | 224,080 KB |
| 最終ジャッジ日時 | 2025-01-23 14:41:43 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int h,w; cin >> h >> w;
vector<ll> mv(4);
for(int i=0;i<4;i++){
cin >> mv[i];
}
ll K,P; cin >> K >> P;
int sx,sy,gx,gy; cin >> sx >> sy >> gx >> gy;
sx--; sy--; gx--; gy--;
vector<string> s(h);
for(int i=0;i<h;i++){
cin >> s[i];
}
vector<vector<ll>> dist(h,vector<ll>(w,1e18));
priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq;
dist[sx][sy]=0;
pq.push({0,{sx,sy}});
while(pq.size()){
auto p=pq.top(); pq.pop();
int x=p.second.first,y=p.second.second;
if(dist[x][y]!=p.first)continue;
for(int i=0;i<4;i++){
int nx=x+dx[i],ny=y+dy[i];
if(0<=nx and nx<h and 0<=ny and ny<w and s[nx][ny]!='#'){
ll cost=p.first+mv[i];
if(s[nx][ny]=='@')cost+=P;
if(dist[nx][ny]>cost){
dist[nx][ny]=cost;
pq.push({cost,{nx,ny}});
}
}
}
}
if(dist[gx][gy]<=K)printf("Yes\n");
else printf("No\n");
}