結果
| 問題 | No.20 砂漠のオアシス |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-05-21 07:28:55 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 5,000 ms |
| コード長 | 1,770 bytes |
| 記録 | |
| コンパイル時間 | 749 ms |
| コンパイル使用メモリ | 151,156 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-26 10:12:01 |
| 合計ジャッジ時間 | 1,851 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.cpp:40:12: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
40 | int L[N][N];
| ^
main.cpp:40:12: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:38:7: note: declared here
38 | int N, V, OX, OY;
| ^
main.cpp:40:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
40 | int L[N][N];
| ^
main.cpp:40:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:38:7: note: declared here
38 | int N, V, OX, OY;
| ^
main.cpp:51:19: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
51 | bool visited[N][N][2];
| ^
main.cpp:51:19: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:38:7: note: declared here
38 | int N, V, OX, OY;
| ^
main.cpp:51:16: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
51 | bool visited[N][N][2];
| ^
main.cpp:51:16: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:38:7: note: declared here
38 | int N, V, OX, OY;
| ^
4 warnings generated.
ソースコード
#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;
}
siman