結果

問題 No.424 立体迷路
ユーザー ScottShelbyScottShelby
提出日時 2020-10-04 06:31:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 177,468 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 22:16:14
合計ジャッジ時間 3,443 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main() {
  int h, w;
  cin >> h >> w;
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  sx--; sy--; gx--; gy--;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  queue<P> q;
  q.push(P(sx, sy));

  vector<vector<bool>> ok(h, vector<bool>(w));
  ok[sx][sy] = true;
  while (!q.empty()) {
    auto p = q.front(); q.pop();
    int x = p.first, y = p.second;
    rep(i, 4) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w || ok[nx][ny]) continue;
      int diff = abs(s[x][y] - s[nx][ny]);
      if (diff >= 2) continue;
      ok[nx][ny] = true;
      q.push(P(nx, ny));
    }

    rep(i, 4) {
      int nx = x + dx[i] * 2;
      int ny = y + dy[i] * 2;
      if (nx < 0 || nx >= h || ny < 0 || ny >= w || ok[nx][ny]) continue;
      int diff = abs(s[x][y] - s[nx][ny]);
      if (diff > 0) continue;
      ok[nx][ny] = true;
      q.push(P(nx, ny));
    }
  }
  string ans = "NO";
  if (ok[gx][gy]) ans = "YES";
  cout << ans << endl;
}
0