結果
| 問題 | 
                            No.424 立体迷路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ScottShelby
                         | 
                    
| 提出日時 | 2020-10-04 06:34:31 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,313 bytes | 
| コンパイル時間 | 1,782 ms | 
| コンパイル使用メモリ | 179,492 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-18 18:03:01 | 
| 合計ジャッジ時間 | 2,393 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 19 WA * 2 | 
ソースコード
#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((int)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((int)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;
}
            
            
            
        
            
ScottShelby