아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Button Lock

시간 제한3초메모리 제한512 MB

요약
주어진 n개의 비트마스크 암호가 실행 중에 적어도 한 번씩 나타나도록 버튼 누름과 RESET으로 이루어진 최단 수열을 구한다.
난이도

보통10점 중 7점

유형
그래프, BFS, 비트 연산, 최단 경로
정답자
아직 제출이 없습니다

문제

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 dd buttons with digits from 00 to d−1d - 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 nn 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 dd and nn (1≤d≤101 \le d \le 10; 1≤n≤2d−11 \le n \le 2^d - 1). Next nn lines describe possible passwords. Each line contains a string s_is\_i of dd zeros and ones: for all jj from 11 to dd the jj-th character is 1 iff the button with the digit j−1j - 1 must be pushed down.

All strings s_is\_i are different, and each string contains at least one 1.

출력

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

힌트

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

예제2

  1. 예제 1

    입력
    2 2
    10
    11
    
    예상 출력
    2
    0 1
    
  2. 예제 2

    입력
    3 4
    001
    111
    101
    011
    
    예상 출력
    6
    2 0 R 1 2 0