結果

問題 No.20 砂漠のオアシス
ユーザー simansiman
提出日時 2021-05-21 07:25:17
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 142,832 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-18 14:14:29
合計ジャッジ時間 2,743 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 12 ms
6,940 KB
testcase_06 AC 10 ms
6,944 KB
testcase_07 AC 22 ms
6,940 KB
testcase_08 AC 13 ms
6,940 KB
testcase_09 AC 26 ms
6,944 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,948 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 7 ms
6,940 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 7 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 (node.y == OY && node.x == OX) {
      node.health *= 2;
      node.use_oasis = true;
    }

    if (node.y == N - 1 && node.x == N - 1) {
      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;
}
0