結果

問題 No.424 立体迷路
ユーザー yuruhiyayuruhiya
提出日時 2020-03-01 20:49:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,668 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 41,392 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 22:26:30
合計ジャッジ時間 1,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize ("Ofast")
#include <cstdio>
#include <cctype>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

// inline int gc()noexcept { return getchar_unlocked(); }
inline int gc()noexcept { return getchar(); }
inline int in()noexcept {
	int v = 0; char c = gc();
	for (; isdigit(c); c = gc()) {
		v *= 10;
		v += c - '0';
	}
	return v;
}

int par[2509];
inline int root(int x)noexcept {
	if (par[x] == x)return x;
	else return par[x] = root(par[x]);
}
inline void unite(int x, int y)noexcept {
	x = root(x); y = root(y);
	if (x == y)return;
	par[y] = x;
}

int s[51][51];

inline bool check(int x, int y)noexcept {
	return x >= y ? x <= y + 1 : y == x + 1;
}

int main() {
	int h = in(), w = in();
	int sx = in() - 1, sy = in() - 1;
	int gx = in() - 1, gy = in() - 1;
	rep(i, h) {
		rep(j, w)s[i][j] = gc() - '0';
		gc();
	}

	int n = h * w;
	rep(i, n)par[i] = i;

	int ind = 0;
	rep(i, h) {
		rep(j, w - 1) {
			if (check(s[i][j], s[i][j + 1])) {
				unite(ind, ind + 1);
			}
			++ind;
		}
		++ind;
	}
	ind = 0;
	rep(i, h - 1) {
		rep(j, w) {
			if (check(s[i][j], s[i + 1][j])) {
				unite(ind, ind + w);
			}
			++ind;
		}
	}
	ind = 0;
	rep(i, h) {
		rep(j, w - 2) {
			if (s[i][j] == s[i][j + 2] && s[i][j] > s[i][j + 1]) {
				unite(ind, ind + 2);
			}
			++ind;
		}
		ind += 2;
	}
	ind = 0;
	rep(i, h - 2) {
		rep(j, w) {
			if (s[i][j] == s[i + 2][j] && s[i][j] > s[i + 1][j]) {
				unite(ind, ind + w + w);
			}
			++ind;
		}
	}

	if (root(sx * w + sy) == root(gx * w + gy)) {
		puts("YES");
	} else {
		puts("NO");
	}
}
0