結果

問題 No.424 立体迷路
ユーザー ldsybldsyb
提出日時 2016-09-23 00:22:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 67,004 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:52:20
合計ジャッジ時間 1,513 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

string b[50];
int h, w, sx, sy, gx, gy, dd[] = {1, 0, -1, 0, 1};
bool visited[50][50];

bool inside(int x, int y){ return 0 <= x && x < h && 0 <= y && y < w;}

bool solve(int x, int y){
	if(gx == x && y == gy) return true;
	if(visited[x][y]) return false;
	bool f = false;
	visited[x][y] = true;
	for(int i = 0; i < 4; i++){
		int nx = x + dd[i], ny = y + dd[i + 1];
		if(inside(nx, ny) && (b[x][y] == b[nx][ny] || b[x][y] == b[nx][ny] + 1 || b[x][y] == b[nx][ny] - 1)) f |= solve(nx, ny);
		int nx2 = x + 2 * dd[i], ny2 = y + 2 * dd[i + 1];
		if(inside(nx2, ny2) && b[x][y] == b[nx2][ny2] && b[x][y] > b[nx][ny]) f |= solve(nx2, ny2);
	}
	return f;
}

int main(){
	cin >> h >> w >> sx >> sy >> gx >> gy;
	for(int i = 0;i < h;i++) cin >> b[i];
	sx--; sy--; gx--; gy--;
	cout << (solve(sx, sy) ? "YES" : "NO") << endl;
}
0