QOJ.ac

QOJ

Límite de tiempo: 1.5 s Límite de memoria: 64 MB Puntuación total: 20

#23774. Common Substring

Estadísticas

Problem

Given $2$ strings, write a program to find the longest string that is contained in both strings, and report its length.

Here, a string $s$ is said to be contained in a string $t$ if $s$ appears contiguously in $t$. The empty string, that is, the string of length $0$, is contained in every string. For example, the string ABRACADABRA contains the following strings: ABRA, RAC, D, ACADABRA, ABRACADABRA, the empty string, and so on. On the other hand, the string ABRACADABRA does not contain the following strings: ABRC, RAA, BA, K, and so on.

Examples

Example $1$: When ABRACADABRA and ECADADABRBCRDARA are given as the strings, the strings contained in both include CA, CADA, ADABR, the empty string, and so on. Among them, the longest one is ADABR, and its length is $5$. The positions of ADABR contained in the $2$ strings are shown in Figure $2\text{-}1$.

$$\begin{aligned} \texttt{ABRAC}&\underline{\texttt{ADABR}}\texttt{A} \\ \texttt{ECAD}&\underline{\texttt{ADABR}}\texttt{BCRDARA} \end{aligned}$$

Figure $2\text{-}1$: Positions of ADABR appearing in the strings of Example $1$

Example $2$: When UPWJCIRUCAXIIRGL and SBQNYBSBZDFNEV are given as the strings, the only string contained in both is the empty string, and its length is $0$.

Input

The input consists of $2$ lines: the $1$-st string is given on the $1$-st line, and the $2$-nd string is given on the $2$-nd line. Each string consists of uppercase English letters, and the length of each string is at least $1$ and at most $4\,000$.

Of the test data, for $30\%$ of the score, the length of each string is at least $1$ and at most $50$.

Output

Print $1$ line containing only the length of the longest string contained in both of the $2$ given strings.

Sample Input and Output

The inputs and outputs corresponding to the examples are as follows.

Sample Input 1

ABRACADABRA
ECADADABRBCRDARA

Sample Output 1

5

Sample Input 2

UPWJCIRUCAXIIRGL
SBQNYBSBZDFNEV

Sample Output 2

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.