Button Lock

题意翻译

有 $d$ 个按钮,编号从 $0$ 到 $d-1$,在按下一个按钮之后,按钮不会复位。有一个重置键,按下这个重置键之后,所有被按下的按钮都会被复位。现在有一些按钮集合,你需要找到一个最短的操作序列,使得每一个集合表示的被按下的状态在整个过程中都出现过至少一次,求这个序列。 输入格式: 第一行两个数字 $d$ 和 $n$,分别表示按钮的数量和集合的数列。 接下来 $n$ 行每行一个长度为 $d$ 的只包含 `0` 和 `1` 的字符串,表示每一个集合。 输出格式: 第一行一个数字 $k$,表示序列的长度。 第二行输出该序列,按钮用编号表示,重置键用 `R` 表示,序列中每两个元素用空格隔开。 如果有多个答案,输出任意一个。

题目描述

You are standing in front of the room with great treasures. The only thing stopping you is the door with a push-button combination lock. This lock has $ d $ buttons with digits from $ 0 $ to $ d - 1 $ . Whenever you press a button, it stays pushed down. You can not pop back up just one button, but there is a "RESET" button — pressing it pops up all other buttons. Initially, no buttons are pushed down. The door instantly opens when some specific set of digits is pushed down. Sadly, you don't know the password for it. Having read the documentation for this specific lock, you found out that there are $ n $ possible passwords for this particular lock. Find the shortest sequence of button presses, such that all possible passwords appear at least once during its execution. Any shortest correct sequence of button presses will be accepted.

输入输出格式

输入格式


The first line contains two integers $ d $ and $ n $ ( $ 1 \le d \le 10 $ ; $ 1 \le n \le 2^d - 1 $ ). Next $ n $ lines describe possible passwords. Each line contains a string $ s_i $ of $ d $ zeros and ones: for all $ j $ from $ 1 $ to $ d $ the $ j $ -th character is 1 iff the button with the digit $ j - 1 $ must be pushed down. All strings $ s_i $ are different, and each string contains at least one 1.

输出格式


On the first line, print the number $ k $ — the minimum number of button presses. On the second line, print $ k $ tokens, describing the sequence. Whenever you press a button with a digit, print that digit. Whenever you press "RESET", print "R".

输入输出样例

输入样例 #1

2 2
10
11

输出样例 #1

2
0 1

输入样例 #2

3 4
001
111
101
011

输出样例 #2

6
2 0 R 1 2 0

说明

In the second example, the sequence 1 2 R 2 0 1 is also possible.