結果

問題 No.424 立体迷路
ユーザー nak3nak3
提出日時 2017-03-26 14:15:33
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,541 bytes
コンパイル時間 1,378 ms
コンパイル使用メモリ 151,312 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 11:01:13
合計ジャッジ時間 4,097 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int h, w;
	cin >> h >> w;
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;

	string b[h+1];
	for (int i = 1; i <= h; i++) {
		cin >> b[i];
	}

	bool rec[h+1][w+1];
	for (int i = 0; i <= h; i++) {
		for (int j = 0; j <= w; j++) {
			rec[i][j] = false;
		}
	}
	// start


	queue<P> q;
	q.push(P(sx,sy));
	while (true) {
		if (q.empty()) {
			cout << "NO" << "\n";
			return 0;
		}
		P tmp = q.front(); q.pop();
		int x = tmp.first;
		int y = tmp.second;
		if (x==gx&&y==gy) {
			cout << "YES" << "\n";
			return 0;
		}

//		cout << "debug " << x << " " << y << "\n";

		if (rec[x][y]) {
			continue;
		}
		if (x-1>=1&&abs((b[x][y-1]-'0')-(b[x-1][y-1]-'0'))<=1) {
			q.push(P(x-1,y));
		}
		if (y-1>=1&&abs((b[x][y-1]-'0')-(b[x][y-1-1]-'0'))<=1) {
			q.push(P(x,y-1));
		}
		if (x+1<=h&&abs((b[x][y-1]-'0')-(b[x+1][y-1]-'0'))<=1) {
			q.push(P(x+1,y));
		}
		if (y+1<=w&&abs((b[x][y-1]-'0')-(b[x][y+1-1]-'0'))<=1) {
			q.push(P(x,y+1));
		}


		if (x-2>=1&&(b[x][y-1]==b[x-2][y-1])&&(b[x+1][y-1]-'0')<=(b[x-2][y-1]-'0')) {
			q.push(P(x-2,y));
		}
		if (y-2>=1&&(b[x][y-1]==b[x][y-2-1])&&(b[x][y-1-1]-'0')<=(b[x][y-2-1]-'0')) {
			q.push(P(x,y-2));
		}
		if (x+2<=h&&(b[x][y-1]==b[x+2][y-1])&&(b[x+1][y]-'0')<=(b[x][y-1]-'0')) {
			q.push(P(x+2,y));
		}
		if (y+2<=w&&(b[x][y-1]==b[x][y+2-1])&&(b[x][y+1-1]-'0')<=(b[x][y+2-1]-'0')) {
			q.push(P(x,y+2));
		}
		rec[x][y] = true;
	}
}
0