QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#9667. L-覆盖检查器

统计

在本题中,你需要实现上一题的输出检查器。

给定一个 $n$ 行 $m$ 列的网格,行从上到下编号为 $1$ 到 $n$,列从左到右编号为 $1$ 到 $m$。现在有无穷多个 $1+1$ L 型瓷砖(如下图所示),你已经使用了一些瓷砖覆盖该网格,但你不确定覆盖是否正确。

你的覆盖方案可以用 $n$ 个长度为 $m$ 的字符串来表示。字符串仅包含六个字符 UDLRC.,其中第 $i$ 行的第 $j$ 个字符表示网格中第 $i$ 行第 $j$ 列的覆盖情况。字符 . 表示该单元格未被覆盖。如果覆盖方案中只有一个 .,且该 . 位于第 $1$ 行第 $m$ 列,则该覆盖方案是正确的;否则,它是错误的。字符 C 表示瓷砖的中心(即图中瓷砖的左下角)。字符 UDLR 分别表示该单元格的上方、下方、左方、右方单元格被该瓷砖的中心所覆盖。如果所有的 L 型瓷砖都是完整的,且每个单元格仅被一个瓷砖覆盖,则该覆盖方案是正确的;否则,它是错误的。

给定一些覆盖方案,请判断这些方案是否正确。

输入格式

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

对于每个测试用例,第一行包含两个整数 $n, m$ ($2 \le n, m \le 500$),表示网格的大小。

接下来有 $n$ 行,每行包含一个长度为 $m$ 的字符串,字符串仅由六个字符 UDLRC. 组成。第 $i$ 行的第 $j$ 个字符表示网格中第 $i$ 行第 $j$ 列的覆盖情况。

保证所有测试用例的 $n \times m$ 之和不超过 $10^6$。

输出格式

对于每个测试用例,如果覆盖方案正确,输出 Yes;否则,输出 No

样例

输入 1

2
4 4
CLD.
UDCL
DCLD
CLRC
2 3
DRC
CLU

输出 1

Yes
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.