結果

問題 No.424 立体迷路
ユーザー hanorverhanorver
提出日時 2016-09-22 22:57:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,580 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 80,632 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:48:55
合計ジャッジ時間 1,782 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>

bool inside(int h, int w, int x, int y) {
	if (x < 0 || y < 0 || x >= h || y >= w) return false;
	return true;
}

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

	std::cin >> h >> w;
	std::cin >> sx >> sy >> gx >> gy;

	sx--;sy--;gx--;gy--;

	std::vector<std::string> d(h);
	for (int i = 0; i < h; i++) {
		std::cin >> d[i];
	}

	std::queue<std::pair<int, int> > p;
	p.push({ sx, sy });

	int visited[50][50] = { 0 };
	int dictx[] = { 1,0,-1,0 }, dicty[] = { 0,1,0,-1 };

	while (!p.empty()) {
		int x, y;
		auto j = p.front(); p.pop();
		x = j.first;
		y = j.second;
		if (visited[x][y]) continue;
		//std::cout << x << " " << y << std::endl;
		visited[x][y] = 1;
		for (int i = 0; i < 4; i++) {
			if (inside(h, w, x + dictx[i], y + dicty[i])) {
				// 同じ高さ
				if (d[x][y] == d[x + dictx[i]][y + dicty[i]]) {
					p.push({ x + dictx[i],y + dicty[i] });
				}
				// 登る
				if (d[x][y] + 1 == d[x + dictx[i]][y + dicty[i]]) {
					p.push({ x + dictx[i],y + dicty[i] });
				}
				// 降りる
				if (d[x][y] - 1 == d[x + dictx[i]][y + dicty[i]]) {
					p.push({ x + dictx[i],y + dicty[i] });
				}
				// 1つ飛び
				if (inside(h, w, x + dictx[i] * 2, y + dicty[i] * 2)) {
					if (d[x + dictx[i]][y + dicty[i]] < d[x][y] && d[x][y] == d[x + dictx[i] * 2][y + dicty[i] * 2]) {
						p.push({ x + dictx[i] * 2,y + dicty[i] * 2});
					}
				}
			}
		}
	}

	if (visited[gx][gy] == 1) {
		std::cout << "YES" << std::endl;
	} else {
		std::cout << "NO" << std::endl;
	}

	return 0;
}
0