题目描述
Problem Description
A coding scheme maps each character to a binary string. For example, {1, 1010, 01, 10101} is a coding scheme that maps four characters (let's assume they are a, b, c, d) to the strings 1, 1010, 01, and 10101 respectively. The encoding of a string is the concatenation of the encodings of its characters. For instance, in the aforementioned coding scheme, the encoding of the string "cac" is 01101, and the encoding of "dcb" is 10101011010.
Further analysis reveals that the previous coding scheme is quite poor, as the encodings of the strings "ba", "acc", and "d" are all 10101. For a given coding scheme, your task is to find three different strings such that their encodings are identical. In other words, find a binary encoding string that can be decoded in at least three different ways. If there are multiple solutions, the encoding string should be as short as possible.
Input Format
The first line contains an integer n, the number of symbols. The following n lines each contain a binary string of length no more than 50 (which may be an empty string), representing the encoding of each symbol.
Output Format
Output a single line containing an integer, which is the length of the shortest encoding. If there is no solution, output -1.
Sample Input and Output
Sample Input #1
4
1
1010
01
10101
Sample Output #1
5
Sample Input #2
2
0
1
Sample Output #2
-1
Sample Input #3
7
00011011
000110
11
0001
1011
00
011011
Sample Output #3
8
Notes
2 <= n <= 30
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分