結果
問題 |
No.20 砂漠のオアシス
|
ユーザー |
![]() |
提出日時 | 2021-05-21 07:28:55 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 33 ms / 5,000 ms |
コード長 | 1,770 bytes |
コンパイル時間 | 1,838 ms |
コンパイル使用メモリ | 141,688 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 07:27:16 |
合計ジャッジ時間 | 2,002 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#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; int health; bool use_oasis; Node(int y = -1, int x = -1, int health = -1, bool use_oasis = false) { this->y = y; this->x = x; this->health = health; this->use_oasis = use_oasis; } bool operator>(const Node &n) const { return health < n.health; } }; int main() { int N, V, OX, OY; cin >> N >> V >> OX >> OY; int L[N][N]; --OX; --OY; for (int y = 0; y < N; ++y) { for (int x = 0; x < N; ++x) { cin >> L[y][x]; } } priority_queue <Node, vector<Node>, greater<Node>> pque; pque.push(Node(0, 0, V)); bool visited[N][N][2]; memset(visited, false, sizeof(visited)); while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.y][node.x][node.use_oasis]) continue; visited[node.y][node.x][node.use_oasis] = true; if (not node.use_oasis && node.y == OY && node.x == OX) { node.health *= 2; node.use_oasis = true; } if (node.y == N - 1 && node.x == N - 1) { cerr << node.health << endl; 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 || N <= ny || N <= nx) continue; int nh = node.health - L[ny][nx]; if (nh <= 0) continue; pque.push(Node(ny, nx, nh, node.use_oasis)); } } cout << "NO" << endl; return 0; }