結果

問題 No.424 立体迷路
ユーザー roiti46roiti46
提出日時 2016-10-10 22:16:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,675 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 149,792 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:57:24
合計ジャッジ時間 2,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int h, w;
int sx, sy, gx, gy;
int b[55][55];
bool used[55][55];

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

bool is_inside(int x, int y) {
  return (0 <= x && x < w && 0 <= y && y < h);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> h >> w;
  cin >> sy >> sx >> gy >> gx;
  sx--; sy--; gx--; gy--;
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) b[i][j] = s[j] - '0';
  }

  queue<pair<int, int>> que;
  que.push({sx, sy});
  while (!que.empty()) {
    auto p = que.front(); que.pop();
    int x = p.first, y = p.second;
    if (used[y][x]) continue;
    used[y][x] = true;
    if (x == gx && y == gy) break;

    rep(i, 4) {
      int nx = x + dx[i], ny = y + dy[i];
      //cout << (nx < w) << " " << (ny < h) << endl;
      if (!is_inside(nx, ny)) continue;
      if (used[ny][nx]) continue;
      if (abs(b[ny][nx] - b[y][x]) <= 1) que.push({nx, ny});
    }
    rep(i, 4) {
      int nx = x + dx[i], ny = y + dy[i];
      int n2x = x + 2*dx[i], n2y = y + 2*dy[i];
      if (!is_inside(n2x, n2y)) continue;
      if (used[n2y][n2x]) continue;
      if (b[y][x] == b[n2y][n2x] && b[ny][nx] < b[n2y][n2x]) que.push({n2x, n2y});
    }
  }

  cout << (used[gy][gx] ? "YES":"NO") << endl;

  return 0;
}
0