結果

問題 No.424 立体迷路
ユーザー rsk0315rsk0315
提出日時 2019-02-01 20:29:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 826 ms
コンパイル使用メモリ 84,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 17:06:26
合計ジャッジ時間 1,827 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <tuple>

static constexpr size_t di[] = {size_t(-1), 0, 1, 0};
static constexpr size_t dj[] = {0, size_t(-1), 0, 1};

int main() {
  size_t h, w;
  scanf("%zu %zu", &h, &w);

  size_t sy, sx, gy, gx;
  scanf("%zu %zu %zu %zu", &sy, &sx, &gy, &gx);
  --sy;
  --sx;
  --gy;
  --gx;

  std::vector<std::string> b(h);
  for (size_t i = 0; i < h; ++i) {
    char buf[64];
    scanf("%s", buf);
    b[i] = buf;
  }

  std::queue<std::pair<size_t, size_t>> q;
  std::vector<std::vector<bool>> vis(h, std::vector<bool>(w));
  q.emplace(sy, sx);
  while (!q.empty()) {
    size_t i, j;
    std::tie(i, j) = q.front();
    q.pop();
    if (vis[i][j]) continue;
    vis[i][j] = true;

    for (int k = 0; k < 4; ++k) {
      size_t ni = i + di[k];
      size_t nj = j + dj[k];
      if (!(ni < h && nj < w)) continue;

      int m0 = b[i][j];
      int m1 = b[ni][nj];
      if (abs(m0-m1) <= 1 && !vis[ni][nj]) {
        q.emplace(ni, nj);
      }

      size_t nni = ni + di[k];
      size_t nnj = nj + dj[k];
      if (!(nni < h && nnj < w)) continue;

      int m2 = b[nni][nnj];
      if (m2 == m0 && m2 > m1 && !vis[nni][nnj]) {
        q.emplace(nni, nnj);
      }
    }
  }

  puts(vis[gy][gx]? "YES":"NO");
}
0