QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#9714. 多彩网格

統計

有一个 $n$ 行 $m$ 列的网格,且 $n \times m$ 为偶数。网格被涂上了 $\frac{n \times m}{2}$ 种颜色。每种颜色恰好占据两个相邻的方块。两个方块相邻意味着它们在网格中共享一条边。我们将 $(x, y)$ 定义为第 $x$ 行第 $y$ 列的方块。

小马(Little Horse)在网格上行走。每次他可以移动到相邻的方块,但他不能移动到与当前位置颜色相同的方块。现在,我们给出 $k$ 个条件。在每个条件中,我们给出两个位置 $(x_1, y_1)$ 和 $(x_2, y_2)$,并告诉你小马是否能从一个位置移动到另一个位置。你需要构造一个满足所有条件的网格。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 100$),表示测试用例的数量。

每个测试用例的第一行包含三个整数 $n, m, k$ ($1 \le n \times m \le 10^5$, $n \times m$ 为偶数, $1 \le k \le 10^5$),分别表示网格的行数、列数和条件数量。$n \times m$ 的总和与 $k$ 的总和均不超过 $2 \times 10^5$。

接下来的 $k$ 行,每行包含五个整数 $x_1, y_1, x_2, y_2, c$ ($1 \le x_1, x_2 \le n, 1 \le y_1, y_2 \le m, 0 \le c \le 1$)。

  • $c = 0$:小马无法从 $(x_1, y_1)$ 移动到 $(x_2, y_2)$。
  • $c = 1$:小马可以从 $(x_1, y_1)$ 移动到 $(x_2, y_2)$。

输出格式

对于第 $x$ 个测试用例,如果没有可能的解,输出 Case #x: No

否则,输出 Case #x: Yes,然后输出 $n$ 行。每行是一个长度为 $m$ 的字符串,仅包含 L, R, D, U。对于第 $x$ 行的第 $y$ 个字符:

  • L:$(x, y)$ 与 $(x, y - 1)$ 颜色相同。
  • R:$(x, y)$ 与 $(x, y + 1)$ 颜色相同。
  • D:$(x, y)$ 与 $(x + 1, y)$ 颜色相同。
  • U:$(x, y)$ 与 $(x - 1, y)$ 颜色相同。

如果存在多种解,输出任意一种即可。

样例

输入 1

4
2 2 1
1 1 1 2 1
2 2 1
1 1 2 1 1
2 2 1
1 1 2 2 1
2 2 2
1 1 1 2 0
1 1 2 1 0

输出 1

Case #1: Yes
DD
UU
Case #2: Yes
RL
RL
Case #3: No
Case #4: No

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.