Post's Correspondence Problem | 프로그래밍의 벗 PivotOJ
PivotOJ

Post's Correspondence Problem

시간 제한: 1000ms메모리 제한: 128MB출처: CCC 2001 SeniorBOJ 6935

문제

Let AA and BB be two sequences of non-empty strings:

A=(a1,a2,,an)B=(b1,b2,,bn)\displaystyle \begin{align*} A &= (a_1, a_2, \dots, a_n) \\ B &= (b_1, b_2, \dots, b_n) \end{align*}

Let mm be a positive integer. Does there exist a sequence of integers i1,i2,,iki_1, i_2, \dots, i_k such that m>k>0m > k > 0 and ai1ai2aik=bi1bi2bika_{i_1} a_{i_2} \dots a_{i_k} = b_{i_1} b_{i_2} \dots b_{i_k}?

For example, if A=(a,abaaa,ab)A = (a, abaaa, ab) and B=(aaa,ab,b)B = (aaa, ab, b), then the required sequence of integers is (2,1,1,3)(2, 1, 1, 3) giving abaaaaaab=abaaaaaababaaaaaab = abaaaaaab.

입력

The first two lines of input will contain mm and nn respectively, and m×n40m \times n \le 40. The next 2n2n lines contain in order the elements of AA followed by the elements of BB. Each string is at most 2020 characters.

출력

If a solution exists, print kk on a line by itself, followed by the integer sequence in order, one element per line. Otherwise, print a single line containing No solution..

예제

예제 1

입력
7
3
a
abaaa
ab
aaa
ab
b
출력
4
2
1
1
3

예제 2

입력
10
3
abc
def
ghi
bcd
efg
hia
출력
No solution.
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.