結果

問題 No.424 立体迷路
ユーザー こまるこまる
提出日時 2020-10-20 00:36:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,567 bytes
コンパイル時間 1,860 ms
コンパイル使用メモリ 175,928 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 13:31:27
合計ジャッジ時間 2,903 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace fastio {
static constexpr int SZ = 1 << 17;
char ibuf[SZ], obuf[SZ];
int pil = 0, pir = 0, por = 0;

struct Pre {
  char num[40000];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i * 4 + j] = n % 10 + '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
}
inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

inline void rd(char &c) { c = ibuf[pil++]; }
template <typename T> inline void rd(T &x) {
  if (pil + 32 > pir)
    load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if (c == '-') {
    minus = 1;
    c = ibuf[pil++];
  }
  x = 0;
  while (c >= '0') {
    x = x * 10 + (c & 15);
    c = ibuf[pil++];
  }
  if (minus)
    x = -x;
}
inline void rd() {}
template <typename Head, typename... Tail>
inline void rd(Head &head, Tail &... tail) {
  rd(head);
  rd(tail...);
}

inline void wt(char c) { obuf[por++] = c; }
template <typename T> inline void wt(T x) {
  if (por > SZ - 32)
    flush();
  if (!x) {
    obuf[por++] = '0';
    return;
  }
  if (x < 0) {
    obuf[por++] = '-';
    x = -x;
  }
  int i = 12;
  char buf[16];
  while (x >= 10000) {
    memcpy(buf + i, pre.num + (x % 10000) * 4, 4);
    x /= 10000;
    i -= 4;
  }
  int d = x < 100 ? (x < 10 ? 1 : 2) : (x < 1000 ? 3 : 4);
  memcpy(obuf + por, pre.num + x * 4 + 4 - d, d);
  por += d;
  memcpy(obuf + por, buf + i + 4, 12 - i);
  por += 12 - i;
}

inline void wt() {}
template <typename Head, typename... Tail>
inline void wt(Head head, Tail... tail) {
  wt(head);
  wt(tail...);
}
template <typename T> inline void wtn(T x) { wt(x, '\n'); }

struct Dummy {
  Dummy() { atexit(flush); }
} dummy;

} // namespace fastio
using fastio::rd;
using fastio::wt;
using fastio::wtn;

struct UnionFind {
  vector<int> data;
  UnionFind(int N) : data(N, -1) {}
  int find(int k) { return data[k] < 0 ? k : data[k] = find(data[k]); }
  bool unite(int x, int y) {
    if ((x = find(x)) == (y = find(y)))
      return false;
    if (data[x] > data[y])
      swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  int size(int k) { return -data[find(k)]; }
  bool same(int x, int y) { return find(x) == find(y); }
};

void run_yukicoder_No424() {
  int h, w;
  rd(h, w);
  UnionFind uf(h * w);
  int sx, sy, gx, gy;
  rd(sx, sy, gx, gy);
  --sx, --sy, --gx, --gy;
  int b[64][64];
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      b[i][j] = s[j] - '0';
    }
  }
  static const int dx[4] = {1, 0, -1, 0};
  static const int dy[4] = {0, 1, 0, -1};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int d = 0; d < 4; d++) {
        int xx = j + dx[d];
        int yy = i + dy[d];
        if (xx < 0 || xx >= w || yy < 0 || yy >= h)
          continue;
        if (abs(b[yy][xx] - b[i][j]) <= 1) {
          uf.unite(i * w + j, yy * w + xx);
        } else if (b[yy][xx] < b[i][j]) {
          int xxx = xx + dx[d], yyy = yy + dy[d];
          if (xxx < 0 || xxx >= w || yyy < 0 || yyy >= h)
            continue;
          if (b[yyy][xxx] == b[i][j])
            uf.unite(i * w + j, yyy * w + xxx);
        }
      }
    }
  }
  bool ans = uf.same(sy * w + sx, gy * w + gx);
  cout << (ans ? "YES" : "NO") << endl;
}


int main() {
  run_yukicoder_No424();
  return 0;
}
0