#D1058. Code
Code
题面翻译
Lucy 正在学习算法,但是她学的不是很好。
她根据所学的内容,给长度为 的字符集构造了一个编码表。
比如,当 时,她构造了这样的一个编码表:。
然后,她会用这个表去压缩数据。
比如:。
但是在某些例子中,她的编码是有歧义的。比如 既可以解码为 "ab",又可以解码为 "c"。
她的体育老师找到了这个问题,并且告诉了她。但是她不这么认为。
现在请帮他的体育老师找到一个最短的 串,使得至少包含两种解码方法。
输入格式
第一行包括一个正整数 ,即字符集的大小。
接下来 行,第 行包括一个 串 ,代表第 个字符。
所有 之和不超过 ,对于每一对 ,
输出格式
如果答案存在,输出答案。否则输出 。
题目描述
Lucy is studying coding algorithm , but she doesn't study well .
According to what she learned, she constructed a coding table for the character set with length .
For example , , she constructed the coding table like this : .
Then , she used the table to compress data . For example : .
But in some cases, her code will be ambiguous . Such as can decoding as both ''ab'' or ''c'' .
Her physical education teacher found this problem and told her , but she didn't think so .
Now please help her physical education teacher find the minimum length of string , which has at least two decoding methods .
输入格式
The first line contains one integer , indicates the size of character set .
Then lines , the line contains a string , represents the code of the character .
The sum of will not exceed , for every pair , .
输出格式
If the answer exists , print the answer , otherwise print instead .
样例 #1
样例输入 #1
3
0
1
01
样例输出 #1
2
样例 #2
样例输入 #2
4
00
01
11
10
样例输出 #2
-1