結果

問題 No.424 立体迷路
ユーザー kk
提出日時 2020-05-30 23:19:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,421 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 176,308 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 05:43:46
合計ジャッジ時間 2,711 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int h, w;
  cin >> h >> w;
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  --sx, --sy, --gx, --gy;
  vector<string> bd(h);
  REP(i, h)
    cin >> bd[i];

  queue<pair<int, int> > q;
  vector<vector<bool> > vis(h, vector<bool>(w));
  vis[sx][sy] = true;
  q.emplace(sx, sy);
  
  while (!q.empty()) {
    int x, y;
    tie(x, y) = q.front();
    q.pop();

    // neighbor
    REP (k, 4) {
      int xt = x + dx[k];
      int yt = y + dy[k];
      if (xt < 0 || xt >= h) continue;
      if (yt < 0 || yt >= w) continue;
      if (abs(bd[x][y] - bd[xt][yt]) < 2 && !vis[xt][yt]) {
        vis[xt][yt] = true;
        q.emplace(xt, yt);
      }
    }
    // jump
    REP(k, 4) {
      int xt = x + 2 * dx[k];
      int yt = y + 2 * dy[k];
      if (xt < 0 || xt >= h) continue;
      if (yt < 0 || yt >= w) continue;
      
      if (bd[x][y] == bd[xt][yt] && bd[x][y] > bd[x+dx[k]][y+dy[k]] && !vis[xt][yt]) {
        vis[xt][yt] = true;
        q.emplace(xt, yt);
      }
    }
  }
  
  if (vis[gx][gy])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}
0