結果

問題 No.20 砂漠のオアシス
ユーザー kk
提出日時 2021-02-25 22:12:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,223 bytes
コンパイル時間 2,401 ms
コンパイル使用メモリ 216,012 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 22:24:31
合計ジャッジ時間 3,658 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 3 ms
6,548 KB
testcase_04 AC 3 ms
6,548 KB
testcase_05 AC 8 ms
6,548 KB
testcase_06 AC 6 ms
6,548 KB
testcase_07 AC 30 ms
6,548 KB
testcase_08 AC 9 ms
6,548 KB
testcase_09 AC 24 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 3 ms
6,548 KB
testcase_15 AC 3 ms
6,548 KB
testcase_16 AC 5 ms
6,548 KB
testcase_17 AC 3 ms
6,548 KB
testcase_18 AC 5 ms
6,548 KB
testcase_19 AC 4 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int rm[200][200][2];

int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, v, ox, oy;
  cin >> n >> v >> ox >> oy;
  --ox, --oy;

  vector<vector<int> > bd(n, vector<int>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      cin >> bd[i][j];

  queue<tuple<int, int, int, int> > q;
  q.emplace(0, 0, 1, v);
  rm[0][0][1] = v;
  
  while (!q.empty()) {
    int y, x, has, vital;
    tie(y, x, has, vital) = q.front();
    q.pop();
    if (rm[y][x][has] > vital)
      continue;
    for (int k = 0; k < 4; k++) {
      int y2 = y + dy[k];
      int x2 = x + dx[k];
      if (x2 < 0 || x2 >= n) continue;
      if (y2 < 0 || y2 >= n) continue;
      if (vital <= bd[y2][x2]) continue;
      int vital2 = vital - bd[y2][x2];
      int has2 = has;
      if (has2 && y2 == oy && x2 == ox) {
        vital2 *= 2;
        has2 = 0;
      }
      if (vital2 > rm[y2][x2][has2]) {
        q.emplace(y2, x2, has2, vital2);
        rm[y2][x2][has2] = vital2;
      }
    }
  }
  
  if (rm[n-1][n-1][0] || rm[n-1][n-1][1])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}
0