結果

問題 No.424 立体迷路
ユーザー ryofjtryofjt
提出日時 2016-09-26 03:57:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 39,840 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:55:41
合計ジャッジ時間 1,269 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

int n, m, sx, sy, gx, gy;
char x[50][51];
bool d[50][50];

bool range(int a, int b){
	return  0 <= a && a < n && 0 <= b &&  b < m;
}

void dfs(int a, int b){
	rep(i, 4){
		int p = dx[i], q = dy[i];
		if(range(a + p, b + q) && !d[a + p][b + q] && abs(x[a + p][b + q] - x[a][b]) <= 1){
			d[a + p][b + q] = true;
			dfs(a + p, b + q);
		}
		if(range(a + p * 2, b + q * 2) && !d[a + p * 2][b + q * 2] && x[a + p][b + q] < x[a][b] && x[a + p * 2][b + q * 2] == x[a][b]){
			d[a + p * 2][b + q * 2] = true;
			dfs(a + p * 2, b + q * 2);
		}
	}
}

int main(){
	scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &gx, &gy);
	--sx; --sy; --gx; --gy;
	rep(i, n){
		scanf("%s", x[i]);
		rep(j, m){
			x[i][j] -= '0';
		}
	}

	d[sx][sy] = true;
	dfs(sx, sy);
	printf("%s\n", d[gx][gy] ? "YES" : "NO");
	return 0;
}
0