#x1041. CF427D Match&Catch
CF427D Match&Catch
Match & Catch
题面翻译
给定两个字符串,求最短的满足各只出现一次的连续公共字串
题目描述
Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings and from two different frequencies as signals. They are suspecting that these two strings are from two different criminals and they are planning to do some evil task.
Now they are trying to find a common substring of minimum length between these two strings. The substring must occur only once in the first string, and also it must occur only once in the second string.
Given two strings and consist of lowercase Latin letters, find the smallest (by length) common substring of both and , where is a unique substring in and also in . See notes for formal definition of substring and uniqueness.
输入格式
The first line of input contains and the second line contains . Both strings consist of lowercase Latin letters.
输出格式
Print the length of the smallest common unique substring of and . If there are no common unique substrings of and print -1.
样例 #1
样例输入 #1
apple
pepperoni
样例输出 #1
2
样例 #2
样例输入 #2
lover
driver
样例输出 #2
1
样例 #3
样例输入 #3
bidhan
roy
样例输出 #3
-1
样例 #4
样例输入 #4
testsetses
teeptes
样例输出 #4
3
提示
Imagine we have string , where is the length of string , and is the letter of the string.
We will call string the substring of the string .
The substring is unique in if and only if there is no pair such that and the substring is equal to the substring in .