結果

問題 No.424 立体迷路
ユーザー ScottShelbyScottShelby
提出日時 2020-10-04 06:51:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,433 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 178,400 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 23:21:00
合計ジャッジ時間 2,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 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 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 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;
    int c = s[x][y] - '0';
    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 nc = s[nx][ny] - '0';
      int diff = abs(c - nc);
      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 nc = s[nx][ny] - '0';
      int diff = abs(c - nc);
      int temae = s[x + dx[i]][y + dy[i]] - '0';
      if (diff > 0 || temae >= nc) continue;
      ok[nx][ny] = true;
      q.push(P(nx, ny));
    }
  }

  string ans = "NO";
  if (ok[gx][gy]) ans = "YES";
  cout << ans << endl;
}
0