Codeforces Round 244 (Div. 2)
D
Match & Catch
Codeforces
2200
原题
← CE →
翻译中…

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.

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

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.

翻译中…

Note

翻译中…

Imagine we have string $*a* = *a*_{1}*a*_{2}*a*_{3}...*a*_{|*a*|}$, where $|*a*|$ is the length of string $*a*$, and $*a*_{*i*}$ is the $*i*^{*th*}$ letter of the string.

翻译中…

We will call string $*a*_{*l*}*a*_{*l* + 1}*a*_{*l* + 2}...*a*_{*r*}$ $(1 ≤ *l* ≤ *r* ≤ |*a*|)$ the substring $[*l*, *r*]$ of the string $*a*$.

翻译中…

The substring $[*l*, *r*]$ is unique in $*a*$ if and only if there is no pair $*l*_{1}, *r*_{1}$ such that $*l*_{1} ≠ *l*$ and the substring $[*l*_{1}, *r*_{1}]$ is equal to the substring $[*l*, *r*]$ in $*a*$.

翻译中…

样例

Input #1
apple
pepperoni
Output #1
2
InputCopy OutputCopy
Input #2
lover
driver
Output #2
1
InputCopy OutputCopy
Input #3
bidhan
roy
Output #3
-1
InputCopy OutputCopy
Input #4
testsetses
teeptes
Output #4
3
InputCopy OutputCopy
题目信息
题号
427D
时间限制
1 s
内存限制
512 MB
标签
动态规划
后缀结构
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。