302228: CF427D. Match & Catch
Memory Limit:512 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Match & Catch
题意翻译
给定两个字符串,求最短的满足各只出现一次的连续公共字串题目描述
Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings $ s_{1} $ and $ s_{2} $ 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 $ s_{1} $ and $ s_{2} $ consist of lowercase Latin letters, find the smallest (by length) common substring $ p $ of both $ s_{1} $ and $ s_{2} $ , where $ p $ is a unique substring in $ s_{1} $ and also in $ s_{2} $ . See notes for formal definition of substring and uniqueness.输入输出格式
输入格式
The first line of input contains $ s_{1} $ and the second line contains $ s_{2} $ $ (1<=|s_{1}|,|s_{2}|<=5000) $ . Both strings consist of lowercase Latin letters.
输出格式
Print the length of the smallest common unique substring of $ s_{1} $ and $ s_{2} $ . If there are no common unique substrings of $ s_{1} $ and $ s_{2} $ print -1.
输入输出样例
输入样例 #1
apple
pepperoni
输出样例 #1
2
输入样例 #2
lover
driver
输出样例 #2
1
输入样例 #3
bidhan
roy
输出样例 #3
-1
输入样例 #4
testsetses
teeptes
输出样例 #4
3