QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#9164. 玩具

Estadísticas

为了给 CEOI 2024 准备题目,科学委员会送给 Ben 一个玩具作为礼物。 这个玩具是一个谜题,可以想象成一个 $H \times W$ 的网格,其中包含一个由两部分组成的金属物体:一个 $1 \times K$ 的水平部分和一个 $L \times 1$ 的垂直部分,它们松散地连接在一起。这两个部分都不能以任何方式旋转,但每个部分都可以独立地垂直或水平滑动,只要它们始终恰好在一个方格上重叠即可。

此外,网格中包含若干障碍物。金属物体的任何部分都不能穿过障碍物。更糟糕的是,这些部分也不能移动到网格之外,哪怕是部分移出也不行。Ben 的任务是将金属物体从指定的起始位置移动到(可能不同的)目标位置,使得两个部分都覆盖在指定的目标方格上。

然而,Ben 玩了一会儿这个玩具,却一直没能解开这个谜题。事实上,他怀疑组织者是在捉弄他,给了他一个无法解开的谜题。因此,他请求你的帮助,判断这个谜题是否可解。

输入格式

输入的第一行包含四个空格分隔的整数 $W, H, K$ 和 $L$,分别表示谜题的宽度、高度、水平部分的宽度和垂直部分的高度。第二行包含四个整数 $x_h, y_h, x_v$ 和 $y_v$,分别表示水平部分最左侧方格的坐标和垂直部分最顶端方格的坐标。

行号从 $0$ 到 $H - 1$(从上到下),列号从 $0$ 到 $W - 1$(从左到右)。$x$ 坐标表示列号,$y$ 坐标表示行号。

接下来的 $H$ 行,每行包含 $W$ 个字符,表示网格。字符 . 表示空方格,字符 X 表示障碍物,字符 * 表示目标方格。

保证金属物体的初始位置是合法的,即两个部分恰好在一个方格上重叠,且两个部分既不与障碍物重叠,也不会超出网格范围。

玩具中只有一个目标方格,即 * 符号在玩具中仅出现一次,它可能与金属物体的初始位置重叠。

输出格式

如果可以将金属物体移动到目标方格,则输出一行 YES,否则输出 NO

样例

样例 1

输入:

4 3 2 2
0 1 0 0
.X.*
....
...X

输出:

YES

初始情况如下:

我们可以通过先将垂直部分向下移动一格,然后交替向右移动垂直部分和水平部分尽可能远的距离来到达目标方格。接着,我们可以将垂直部分向上并向右移动,到达目标方格,最后将水平部分向上移动,也到达目标位置。

样例 2

输入:

2 3 2 3
0 1 0 0
.X
.*
.X

输出:

NO

说明:

没有办法在不碰到障碍物的情况下移动垂直部分。因此,它永远无法到达目标方格。

数据范围

  • $2 \le W, H \le 1500$
  • $2 \le K \le W, 2 \le L \le H$
  • $0 \le x_h \le W - K, 0 \le y_h \le H - 1$
  • $0 \le x_v \le W - 1, 0 \le y_v \le H - L$

子任务

  1. (14 分) $W, H \le 50$
  2. (21 分) $W, H \le 90$
  3. (9 分) $W, H \le 300$ 且 $K, L \le 10$
  4. (29 分) $W, H \le 360$
  5. (27 分) 无附加限制

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.