QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 1024 MB Points totaux : 100

#10690. 棋盘格织物

Statistiques

我的一个朋友买了一块布,绿底白格。当她拿给我们看时,一位酷爱围棋的同学评论道:“啊,这看起来像个棋盘。”我补充说:“对我来说,它看起来更像稿纸。”另一位被称为“大胃王”的同学插嘴道:“它真让我想起绿豆糕。”我们不禁大笑起来。同一块布,每个人看到的却各不相同。朋友急忙用纸把布包起来,心想布就是布——不是棋盘,不是稿纸,当然也不是绿豆糕。

她首先将整块布染成了白色。现在,她想要应用她设计的一种彩色图案。这块布可以看作一个 $N$ 行 $M$ 列的网格,网格中的每个单元格都有其特定的颜色。每种颜色由 $0$ 到 $10^9$ 之间的整数表示。最初,所有单元格的颜色均为 $0$(即白色)。每次染色时,她必须先选择一种特定的颜色,然后选择布的一行或一列进行染色。操作完成后,所选行或列中单元格的颜色将被替换为所选颜色,无论其之前的颜色是什么。

朋友向你展示了她希望染出的图案。请编写一个程序来确定染出该图案所需的操作序列,或者判断是否无法实现。注意,你不需要最小化操作次数,但操作次数不得超过 $N + M$。

输入格式

第一行包含两个整数 $N$ 和 $M$,表示布的大小($1 \le N, M \le 10^5$)。 接下来的 $N$ 行,每行包含 $M$ 个整数 $c_{i,1}, c_{i,2}, \dots, c_{i,M}$,描述了期望的布料颜色图案。第 $i$ 行第 $j$ 列的单元格应染成颜色 $c_{i,j}$($0 \le c_{i,j} \le 10^9$)。

输出格式

如果无法在 $N + M$ 次操作内实现期望的图案,输出 $-1$。 否则,在第一行输出一个整数 $K$,表示要执行的操作次数($0 \le K \le N + M$)。在接下来的 $K$ 行中,每行输出一个大写字母 $d_i$ 和两个整数 $p_i$ 和 $s_i$,描述序列中的第 $i$ 次操作($d_i \in \{\text{R}, \text{C}\}; 0 \le s_i \le 10^9$)。如果字母 $d_i$ 为 R,表示该操作是将布的第 $p_i$ 行染成颜色 $s_i$(且 $1 \le p_i \le N$);如果字母 $d_i$ 为 C,表示该操作是将布的第 $p_i$ 列染成颜色 $s_i$(且 $1 \le p_i \le M$)。

样例

样例输入 1

3 3
0 1 0
2 2 2
0 1 0

样例输出 1

2
C 2 1
R 2 2

样例输入 2

3 3
3 1 4
1 5 9
2 6 5

样例输出 2

-1

样例输入 3

3 4
0 0 0 0
0 0 0 0
0 0 0 0

样例输出 3

0

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.