結果

問題 No.424 立体迷路
ユーザー autumn-eelautumn-eel
提出日時 2016-09-22 22:46:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 143,956 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:45:41
合計ジャッジ時間 2,237 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int h, w, sx, sy, gx, gy;
int mp[50][50];
bool flag[50][50];
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int dx2[]{ 2,-2,0,0 }, dy2[]{ 0,0,2,-2 };

void dfs(int x, int y) {
	flag[x][y] = true;
	rep(i, 4) {
		int nx = x + dy[i], ny = y + dx[i];
		if (0 <= nx&&nx < h && 0 <= ny&&ny < w && !flag[nx][ny] && abs(mp[x][y] - mp[nx][ny]) <= 1)
			dfs(nx, ny);
	}
	rep(i, 4) {
		int nx = x + dx2[i], ny = y + dy2[i];
		if (0 <= nx&&nx < h && 0 <= ny&&ny < w && !flag[nx][ny] && mp[x][y] == mp[nx][ny] && mp[x + dx2[i] / 2][y + dy2[i] / 2] < mp[x][y])
			dfs(nx, ny);
	}
}
int main() {
	scanf("%d%d%d%d%d%d", &h, &w, &sx, &sy, &gx, &gy);
	sx--; sy--; gx--; gy--;
	rep(i, h)rep(j, w)scanf("%1d", &mp[i][j]);
	dfs(sx, sy);
	puts(flag[gx][gy] ? "YES" : "NO");
}
0