結果

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

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>
using namespace std;
template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
using ll = long long;
int main(){
ll H, W, K, P, h, w, nh, nw, sh, sw, gh, gw, alt, d;
cin >> H >> W;
vector<ll> cost(4);
for (int i=0; i<4; i++) cin >> cost[i];
cin >> K >> P >> sh >> sw >> gh >> gw;
sh--; sw--; gh--; gw--;
pq<tuple<ll, ll, ll>> que;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
vector<vector<ll>> dist(H, vector<ll>(W, 1e18));
vector<vector<bool>> visit(H, vector<bool>(W));
vector<string> field(H);
for (int i=0; i < H; i++){
cin >> field[i];
}
dist[sh][sw] = 0;
que.push({0, sh, sw});
while(!que.empty()){
tie(d, h, w) = que.top();
que.pop();
if (visit[h][w]) continue;
visit[h][w] = 1;
for (int dir=0; dir < 4; dir++){
alt = dist[h][w] + cost[dir];
nh = h + dx[dir];
nw = w + dy[dir];
if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
if (field[nh][nw] == '#') continue;
if (field[nh][nw] == '@') alt += P;
if (alt < dist[nh][nw]){
dist[nh][nw] = alt;
que.push({dist[nh][nw], nh, nw});
}
}
}
cout << (dist[gh][gw] <= K ? "Yes" : "No") << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0