QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#6615. 穿越迷宫

Statistiques

“Ad astra abyssoque.”

来自提瓦特的冒险家们被困在一个 $a \times b$ 的矩形迷宫中,迷宫外围被墙壁包围。迷宫的地板非常脆弱,任何时候都不允许两名冒险家移动到同一个格子或停留在同一个格子里。

当他们试图穿过迷宫时,他们发现迷宫中有 $n$ 条逃生绳,并且意识到迷宫中逃生绳的数量与被困的冒险家数量完全相同。然而,这些逃生绳质量很差,当一名冒险家利用它逃离迷宫时,绳子会立即断裂。

每一秒,每名冒险家都可以独立且同时地从格子 $(x, y)$ 移动到迷宫中的左侧格子 $(x, y - 1)$、右侧格子 $(x, y + 1)$、上方格子 $(x - 1, y)$、下方格子 $(x + 1, y)$,或者原地不动。当移动后到达一个包含完好逃生绳的格子时,冒险家可以决定立即利用该逃生绳逃离迷宫(随后绳子断裂),或者留在迷宫中并将逃生绳留给其他人。注意,如果冒险家初始就位于包含逃生绳的格子上,也可以在移动前离开迷宫。

旅行者荧想要引导所有被困的冒险家尽快穿过迷宫,以便她能继续寻找她的家人。

输入格式

第一行包含三个正整数 $n$ ($1 \le n \le 100$),$a$ 和 $b$ ($1 \le a, b \le 100, 1 \le a \times b \le 100$),分别表示被困在迷宫中的冒险家数量、迷宫中的逃生绳数量以及迷宫的行数和列数。

接下来 $n$ 行,每行包含两个整数 $s_x$ ($1 \le s_x \le a$) 和 $s_y$ ($1 \le s_y \le b$),表示一名冒险家初始位于迷宫中的格子 $(s_x, s_y)$。所有冒险家初始位于不同的格子上。

接下来 $n$ 行,每行包含两个整数 $e_x$ ($1 \le e_x \le a$) 和 $e_y$ ($1 \le e_y \le b$),表示迷宫中位于格子 $(e_x, e_y)$ 的一条逃生绳。所有逃生绳位于不同的格子上。

保证初始时至少有一名冒险家位于没有逃生绳的格子上。

输出格式

第一行包含一个整数 $t$,表示所有被困冒险家穿过迷宫所需的最短时间(秒)。

接下来输出 $n$ 行,每行包含四个整数 $s_x, s_y, e_x, e_y$,后跟一个长度为 $t$ 的字符串。这表示初始位于格子 $(s_x, s_y)$ 的冒险家将通过位于格子 $(e_x, e_y)$ 的逃生绳,按照字符串指示的动作离开迷宫。字符串中的第 $i$ 个字符表示在第 $i$ 秒采取的动作,其中 L 表示向左移动,R 表示向右移动,U 表示向上移动,D 表示向下移动,S 表示原地不动,P 表示冒险家已经离开迷宫且不再返回。

如果有多种方案,输出任意一种即可。

样例

样例输入 1

3 4 4
1 1
1 4
4 4
1 3
2 3
2 4

样例输出 1

2
1 1 1 3 RR
1 4 2 3 DL
4 4 2 4 UU

样例输入 2

3 2 2
1 1
1 2
2 2
1 1
2 1
2 2

样例输出 2

1
1 1 1 1 P
1 2 2 2 D
2 2 2 1 L

样例输入 3

2 3 3
1 1
1 3
1 2
2 2

样例输出 3

2
1 1 2 2 DR
1 3 1 2 LP

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.