結果
問題 | No.1638 Robot Maze |
ユーザー |
![]() |
提出日時 | 2021-08-08 18:33:41 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,858 bytes |
コンパイル時間 | 3,015 ms |
コンパイル使用メモリ | 141,848 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 15:15:18 |
合計ジャッジ時間 | 4,595 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
#include <cassert>#include <cmath>#include <algorithm>#include <iostream>#include <iomanip>#include <limits.h>#include <map>#include <queue>#include <set>#include <string.h>#include <vector>using namespace std;typedef long long ll;const int DY[4] = {-1, 0, 1, 0};const int DX[4] = {0, 1, 0, -1};struct Node {int y;int x;ll cost;Node(int y = -1, int x = -1, ll cost = -1) {this->y = y;this->x = x;this->cost = cost;}bool operator>(const Node &n) const {return cost > n.cost;}};int main() {int H, W;cin >> H >> W;ll U, D, R, L, K, P;cin >> U >> D >> R >> L >> K >> P;int sx, sy, tx, ty;cin >> sy >> sx >> ty >> tx;char C[H + 1][W + 1];for (int y = 1; y <= H; ++y) {for (int x = 1; x <= W; ++x) {cin >> C[y][x];}}priority_queue <Node, vector<Node>, greater<Node>> pque;pque.push(Node(sy, sx, 0));bool visited[H + 1][W + 1];memset(visited, false, sizeof(visited));while (not pque.empty()) {Node node = pque.top();pque.pop();if (node.cost > K) continue;if (visited[node.y][node.x]) continue;visited[node.y][node.x] = true;// fprintf(stderr, "[%d, %d] cost: %lld\n", node.y, node.x, node.cost);if (node.y == ty && node.x == tx) {cout << "Yes" << endl;return 0;}for (int direct = 0; direct < 4; ++direct) {int ny = node.y + DY[direct];int nx = node.x + DX[direct];if (ny <= 0 || nx <= 0 || H < ny || W < nx) continue;if (C[ny][nx] == '#') continue;ll ncost = node.cost;if (C[ny][nx] == '@') ncost += P;if (direct == 0) ncost += U;if (direct == 1) ncost += R;if (direct == 2) ncost += D;if (direct == 3) ncost += L;pque.push(Node(ny, nx, ncost));}}cout << "No" << endl;return 0;}