QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 1024 MB 満点: 10

#8411. 谜题 3 [C]

統計

Bajtek 热衷于玩手机游戏。然而,他经常被那些广告所困扰,广告中玩家的操作非常糟糕,旨在引起观众的挫败感并诱导他们下载游戏。其中一个广告(你们可能也见过)给 Bajtek 留下了深刻的印象。

由于灵感可以来源于任何事物,Bajtek 决定基于上述游戏创建一个任务。他选择了一个 $n \times m$ 的目标彩色棋盘,并从一个没有任何颜色的 $n \times m$ 棋盘开始游戏。在一次移动中,他可以选择一行或一列,并将该行或该列中的所有格子涂上他选择的颜色(请注意,这比上述图片中展示的游戏给予了他更大的自由度,因为在图片中,行和列的颜色是预先设定的)。为了使任务形式化,他用大写英文字母标记了所有颜色。你能帮助他编写一个程序,对于他给出的每一个棋盘,输出一个能够正确生成目标颜色布局的移动序列吗?你可以假设输入数据保证可以在最多 $n + m$ 次移动内达到目标。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 2000$),分别表示棋盘的高度和宽度。

接下来的 $n$ 行,每行包含 $m$ 个字符,每个字符都是一个大写英文字母;第 $i$ 行的第 $j$ 个字符表示棋盘第 $i$ 行第 $j$ 列格子的目标颜色。

保证给定的颜色布局可以通过题目描述中不超过 $n+m$ 次的移动序列达到。

输出格式

第一行应包含一个整数 $r$ ($1 \le r \le n+m$),表示你想要执行的移动次数。接下来的 $r$ 行,每行应包含一个移动的描述。

一个移动的描述应以字符 ‘R’ 或 ‘K’ 开头,表示你想要涂色的是行还是列(其中 ‘R’ 表示行,‘K’ 表示列)。接着是一个空格,然后是想要涂色的行号或列号。行号从上到下编号为 $1$ 到 $n$,列号从左到右编号为 $1$ 到 $m$。最后,在另一个空格之后,应有一个大写英文字母,表示你想要将选定行或列涂成的颜色。

请注意,你不需要最小化移动次数——只要执行次数不超过 $n + m$ 即可。

样例

样例输入 1

5 5
AAPAA
APPAA
AAPAA
AAPAA
APPPA

样例输出 1

10
R 1 Z
K 4 A
K 2 P
R 5 P
R 4 A
R 3 A
R 1 A
K 5 A
K 3 P
K 1 A

样例输入 2

2 3
AAA
PPP

样例输出 2

2
R 2 P
R 1 A

说明

样例说明:如果在第一个示例测试中,我们假设字母 ‘P’ 代表绿色,字母 ‘A’ 代表黄色,而字母 ‘Z’ 代表蓝色,那么所选的移动序列将按以下方式绘制棋盘:

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.