結果

問題 No.424 立体迷路
ユーザー w10y26w10y26
提出日時 2017-07-03 13:04:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,940 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 98,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 14:02:32
合計ジャッジ時間 1,989 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define ll long long
#define ffor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
int h, w, sx, sy, gx, gy;
string b[51];
int visited[51][51];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
typedef pair<int, int> P;

int bfs() {
  rep(i, h) rep(j, w) visited[i][j] = 0;
  queue<P> que;
  sx--;
  sy--;
  gx--;
  gy--;
  que.push(P(sy, sx));
  visited[sy][sx] = 1;

  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (p.first == gy && p.second == gx) {
      break;
    }

    rep(i, 4) {
      int nx = p.second + dx[i];
      int ny = p.first + dy[i];

      if (0 <= ny && ny < h && 0 <= nx && nx < w && visited[ny][nx] == 0) {
        int h1 = b[ny][nx] - '0';
        int h2 = b[p.first][p.second] - '0';

        if (abs(h1 - h2) <= 1) {
          visited[ny][nx] = 1;
          que.push(P(ny, nx));
        }
      }
    }

    rep(i, 4) {
      int nx = p.second + 2 * dx[i];
      int ny = p.first + 2 * dy[i];
      if (0 <= ny && ny < h && 0 <= nx && nx < w && visited[ny][nx] == 0) {
        int h1 = b[ny][nx] - '0';
        int h2 = b[p.first][p.second] - '0';
        int half = b[(ny + p.first) / 2][(nx + p.second) / 2] - '0';
        if ((h1 == h2) && (h1 - half) > 0) {
          visited[ny][nx] = 1;
          que.push(P(ny, nx));
        }
      }
    }
  }

  return b[gy][gx];
}

int main() {
  scanf("%d%d", &h, &w);
  scanf("%d%d%d%d", &sx, &sy, &gx, &gy);

  rep(i, h) cin >> b[i];

  if (bfs())
    printf("YES\n");
  else
    printf("NO\n");

  return 0;
}
0