問題一覧 > 通常問題

No.424 3D Maze

レベル : / AI推定難易度 : 400 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 295
作問者 : はむこ / テスター : btk
お気に入りにしたユーザー ProblemId : 1326 / 自分の提出
問題文最終更新日: 2026-01-03 23:00:21
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 149 (順位表) の他の問題:

Problem Statement

You are trapped in a $h \times w$ 3D maze. You cannot go outside the frame of the 3D maze.
You are initially at $(s_x, s_y)$. When you reach the goal $(g_x, g_y)$, you can escape by warp.

Using a ladder, you can make the following moves forward, backward, left, and right (you cannot move diagonally).
(1) Walk to an adjacent block of the same height.
(2) Climb to an adjacent block that is exactly 1 higher, by leaning the ladder against it.
(3) Descend to an adjacent block that is exactly 1 lower, by leaning the ladder against it.
(4) Move to a block of the same height two blocks ahead, by laying the ladder across. To lay the ladder across, the block in between must be lower than the block you are currently on (see Sample 3).

Can you escape?

Input

$h\ w$
$s_x\ s_y\ g_x\ g_y$
$b_1$
$\vdots$
$b_h$

$2 \leq h \leq 50$
$2 \leq w \leq 50$
$1 \leq s_x \leq h$
$1 \leq s_y \leq w$
$1 \leq g_x \leq h$
$1 \leq g_y \leq w$
$b_i$ is a string of length $w$ consisting of '0' through '9'. The $j$-th character of $b_i$ represents the height of the block at $(i, j)$.

Output

Output YES if you can escape, and NO if you cannot. Print a newline at the end.

Sample

Sample 1
Input
3 5
3 5 1 1
43000
12023
00014
Output
YES

You can reach the goal by descending 4 times and climbing 4 times with the ladder.

Sample 2
Input
3 5
3 5 1 1
63000
12023
00014
Output
NO
Sample 3
Input
3 5
2 4 2 2
00000
09090
00000
Output
YES

The ladder can also be used horizontally (rule 4).

Sample 4
Input
6 6
6 6 1 1
202020
020202
202020
020202
202020
020202
Output
NO

Even between blocks of the same height, you cannot move diagonally.

Sample 5
Input
10 12
4 1 1 12
879572576859
445569966665
033345689389
011246557476
000224557745
000022346548
000000425665
000002223544
000000003223
000000000243
Output
YES

You can reach the goal by using the ladder horizontally at least 2 times.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。