CCC '01 S5 - Post's Correspondence Problem

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem types
Canadian Computing Competition: 2001 Stage 1, Senior #5

Let A and B be two sequences of non-empty strings:

A=(a1,a2,,an)B=(b1,b2,,bn)

Let m be a positive integer. Does there exist a sequence of integers i1,i2,,ik such that m>k>0 and ai1ai2aik=bi1bi2bik?

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

Input Specification

The first two lines of input will contain m and n respectively, and m×n40. The next 2n lines contain in order the elements of A followed by the elements of B. Each string is at most 20 characters.

Output Specification

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

Sample Input 1

Copy
7
3
a
abaaa
ab
aaa
ab
b

Sample Output 1

Copy
4
2
1
1
3

Sample Input 2

Copy
10
3
abc
def
ghi
bcd
efg
hia

Sample Output 2

Copy
No solution.

Comments