結果
問題 | No.1638 Robot Maze |
ユーザー |
![]() |
提出日時 | 2021-08-14 20:23:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,386 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 215,392 KB |
最終ジャッジ日時 | 2025-01-23 22:12:44 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; using tpll = tuple<ll, ll, ll>; int main(){ const ll INF = 1e18; const vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, 1, -1}; int H, W; cin >> H >> W; vector<ll> cost(4); for(int i = 0; i < 4; i++)cin >> cost[i]; ll K, P; cin >> K >> P; int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; --sx; --sy; --gx; --gy; vector<string> grid(H); for(string &s: grid)cin >> s; priority_queue<tpll, vector<tpll>, greater<tpll>> pq; vector<vector<ll>> dist(H, vector<ll>(W, INF)); vector<vector<bool>> vis(H, vector<bool>(W)); dist[sx][sy] = 0; pq.push({0, sx, sy}); while(pq.size()){ ll d, h, w; tie(d, h, w) = pq.top(); pq.pop(); if(vis[h][w])continue; vis[h][w] = true; for(int i = 0; i < 4; i++){ int nh = h + dx[i], nw = w + dy[i]; ll c = cost[i]; if(nh < 0 || nh > H - 1 || nw < 0 || nw > W - 1)continue; if(grid[nh][nw] == '#')continue; if(grid[nh][nw] == '@')c += P; if(dist[h][w] + c >= dist[nh][nw])continue; dist[nh][nw] = dist[h][w] + c; pq.push({dist[nh][nw], nh, nw}); } } if(dist[gx][gy] > K)cout << "No" << endl; else cout << "Yes" << endl; }