CF427D.Match & Catch

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings s1s_{1} and s2s_{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 s1s_{1} and s2s_{2} consist of lowercase Latin letters, find the smallest (by length) common substring pp of both s1s_{1} and s2s_{2} , where pp is a unique substring in s1s_{1} and also in s2s_{2} . See notes for formal definition of substring and uniqueness.

输入格式

The first line of input contains s1s_{1} and the second line contains s2s_{2} (1<=s1,s2<=5000)(1<=|s_{1}|,|s_{2}|<=5000) . Both strings consist of lowercase Latin letters.

输出格式

Print the length of the smallest common unique substring of s1s_{1} and s2s_{2} . If there are no common unique substrings of s1s_{1} and s2s_{2} print -1.

输入输出样例

  • 输入#1

    apple
    pepperoni
    

    输出#1

    2
    
  • 输入#2

    lover
    driver
    

    输出#2

    1
    
  • 输入#3

    bidhan
    roy
    

    输出#3

    -1
    
  • 输入#4

    testsetses
    teeptes
    

    输出#4

    3
    

说明/提示

Imagine we have string a=a1a2a3...aaa=a_{1}a_{2}a_{3}...a_{|a|} , where a|a| is the length of string aa , and aia_{i} is the ithi^{th} letter of the string.

We will call string alal+1al+2...ara_{l}a_{l+1}a_{l+2}...a_{r} (1<=l<=r<=a)(1<=l<=r<=|a|) the substring [l,r][l,r] of the string aa .

The substring [l,r][l,r] is unique in aa if and only if there is no pair l1,r1l_{1},r_{1} such that l1ll_{1}≠l and the substring [l1,r1][l_{1},r_{1}] is equal to the substring [l,r][l,r] in aa .

首页