結果

問題 No.424 立体迷路
ユーザー motimoti
提出日時 2016-09-22 23:01:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 177,500 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:49:56
合計ジャッジ時間 2,662 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

int main() {

  int H, W ;cin >> H >> W;
  int sy, sx, gy, gx; cin >> sy >> sx >> gy >> gx;
  sy --, sx --, gy --, gx --;
  vector<string> v(H);
  rep(i, H) {
    cin >> v[i];
  }

  queue<pair<int, int>> q;

  vector<vector<bool>> dist(H, vector<bool>(W, 0));
  dist[sy][sx] = 1;
  q.emplace(sy, sx);

  while(!q.empty()) {
    int y, x; tie(y, x) = q.front(); q.pop();

    if(y == gy && x == gx) {
      cout << "YES\n";
      exit(0);
    }

    for(int i=0; i<4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if(in_range(ny, nx, H, W) && !dist[ny][nx]) {
        if(abs(v[y][x] - v[ny][nx]) <= 1) {
          dist[ny][nx] = 1;
          q.emplace(ny, nx);
        }
      }

      ny = y + dy[i] * 2, nx = x + dx[i] * 2;
      if(in_range(ny, nx, H, W) && !dist[ny][nx]) {
        if(v[y][x] > v[y + dy[i]][x + dx[i]] && v[y][x] == v[ny][nx]) {
          dist[ny][nx] = 1;
          q.emplace(ny, nx);
        }
      }
    }
  }

  cout << "NO\n";
  
  return 0;
}
0