結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 11 ms
6,940 KB
testcase_06 AC 9 ms
6,940 KB
testcase_07 AC 31 ms
6,940 KB
testcase_08 AC 13 ms
6,944 KB
testcase_09 AC 26 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 8 ms
6,944 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 6 ms
6,944 KB
testcase_19 AC 8 ms
6,944 KB
testcase_20 AC 2 ms
6,944 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 (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;
}
0