結果
問題 | No.1638 Robot Maze |
ユーザー |
![]() |
提出日時 | 2024-05-21 14:28:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,517 bytes |
コンパイル時間 | 2,500 ms |
コンパイル使用メモリ | 213,548 KB |
最終ジャッジ日時 | 2025-02-21 16:23:49 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}int main() {fast_io();int h, w;cin >> h >> w;int cost[4];long long k, p;cin >> cost[0] >> cost[1] >> cost[2] >> cost[3] >> k >> p;int xs, ys, xt, yt;cin >> xs >> ys >> xt >> yt;xs--, ys--, xt--, yt--;vector<string> c(h);for (int i = 0; i < h; i++) {cin >> c[i];}long long INF = 1e18;vector<vector<long long>> dist(h, vector<long long>(w, INF));dist[xs][ys] = 0;using tlii = tuple<long long, int, int>;priority_queue<tlii, vector<tlii>, greater<tlii>> pq;pq.push({0, xs, ys});vector<vector<bool>> vis(h, vector<bool>(w));int dx[] = {-1, 1, 0, 0};int dy[] = {0, 0, 1, -1};auto is_in = [&](int x, int y) {return x >= 0 && x < h && y >= 0 && y < w;};while (!pq.empty()) {auto [d, x, y] = pq.top();pq.pop();if (vis[x][y]) continue;vis[x][y] = true;for (int dir = 0; dir < 4; dir++) {int nx = x + dx[dir];int ny = y + dy[dir];if (!is_in(nx, ny) || c[nx][ny] == '#') continue;long long w = cost[dir] + (c[nx][ny] == '@' ? p : 0);if (dist[nx][ny] > dist[x][y] + w) {dist[nx][ny] = dist[x][y] + w;pq.push({dist[nx][ny], nx, ny});}}}cout << (dist[xt][yt] <= k ? "Yes" : "No") << endl;}