結果

問題 No.424 立体迷路
ユーザー kyo1kyo1
提出日時 2020-09-05 12:32:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,439 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 214,556 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 19:10:16
合計ジャッジ時間 4,237 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const std::vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};

template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  int sy, sx, gy, gx;
  cin >> sy >> sx >> gy >> gx;
  sy--, sx--, gy--, gx--;
  vector<vector<int>> G(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++) {
      G[i][j] = s[j] - '0';
    }
  }
  vector<vector<bool>> used(H, vector<bool>(W, false));
  used[sy][sx] = true;
  queue<pair<int, int>> que;
  que.push(make_pair(sy, sx));
  while (!que.empty()) {
    auto [y, x] = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
      if (abs(G[y][x] - G[ny][nx]) <= 1 && !used[ny][nx]) {
        used[ny][nx] = true;
        que.push(make_pair(ny, nx));
      }
      int nny = ny + dy[i], nnx = nx + dx[i];
      if (nny < 0 || nny >= H || nnx < 0 || nnx >= W) continue;
      if (G[nny][nnx] == G[y][x] && G[y][x] > G[ny][nx] && !used[nny][nnx]) {
        used[nny][nnx] = true;
        que.push(make_pair(nny, nnx));
      }
    }
  }
  if (used[gy][gx]) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
  return 0;
}
0