Garage Door Code

면접 대비

시간 제한4초메모리 제한1024 MB

요약
관찰된 여러 자릿수 문자열 각각이 실제 K자리 코드를 부분 수열로 포함할 때, 모든 관찰과 일치하는 K자리 코드를 모두 찾아 사전순으로 출력한다.
난이도

보통10점 중 5점

유형
완전 탐색, 문자열, 백트래킹
정답자
아직 제출이 없습니다

문제

There have been an increasing number of laptop thefts in your area lately. After yours was recently stolen, too, you decided that you had enough and are going to do something about it! After asking around, you heard some rumors about where the stolen laptops have been hidden and you want to get your laptop back!

The rumors led you to a particular garage and you have decided to keep an eye on it to try to figure out how to get in. Over the course of the afternoon, you have seen a handful of people come, enter the garage, and then leave.

There's a security keypad on the door. As you have watched carefully, you have observed different people putting in the code, but they enter different numbers of digits. You figure out that some, maybe all, of them are pretending to intersperse additional key presses just to confuse anyone who might be watching them. You look up the keypad manufacturer's webpage and find that the keypad was designed to use codes with a predetermined length of KK digits. Given the set of observations you've made of different individuals "entering" elongated variations of the code (each does contain the correct code), can you determine what the correct code might be? %Or, instead of unique yes/no, what are possible codes (or how many are there) that would be consistent with your set of observations? It is guaranteed that there will always be at least one correct code that matches all observations. There may be multiple codes that match; you must find all matching codes.

입력

The first line of input contains two integers KK (3≤K≤63 \leq K \leq 6), the number of digits specified by the manufacturer for a correct code, and NN (2≤N≤202 \leq N \leq 20), the number of elongated entry code sequences that you observed.

Each of the next NN lines contains a string of at least KK and at most 12 digits (0-9). These are the elongated entry code sequences that you have observed.

출력

Determine all KK-digit codes that match the full set of elongated observations.

On the first line, output MM, the number of codes that match the set of elongated observations. Then output MM lines, each containing one of these matching codes, having sorted them in increasing lexicographic order.

예제3

  1. 예제 1

    입력
    4 3
    21302749
    5230248
    21076724
    
    예상 출력
    1
    2024
    
  2. 예제 2

    입력
    5 7
    0812734225
    162334559
    7512334755
    1002394561
    9321423495
    81237425
    47126345119
    
    예상 출력
    1
    12345
    
  3. 예제 3

    입력
    3 3
    1234
    012345
    11223344
    
    예상 출력
    4
    123
    124
    134
    234