QOJ.ac

QOJ

実行時間制限: 1.5 s メモリ制限: 64 MB 満点: 20

#23774. 공통 부분 문자열

統計

문제

$2$개의 문자열이 주어졌을 때, 두 문자열 모두에 포함되는 문자열 중 가장 긴 것을 찾아 그 길이를 답하는 프로그램을 작성하라.

여기서 문자열 $s$가 문자열 $t$에 포함된다는 것은 $t$ 안에 $s$가 연속해서 나타나는 것을 말한다. 빈 문자열, 즉 길이 $0$인 문자열은 어떤 문자열에나 포함된다. 예를 들어 문자열 ABRACADABRA에는 다음 문자열이 포함된다: ABRA, RAC, D, ACADABRA, ABRACADABRA, 빈 문자열 등. 반면 문자열 ABRACADABRA에는 다음 문자열은 포함되지 않는다: ABRC, RAA, BA, K 등.

예

예 $1$: 문자열로 ABRACADABRA와 ECADADABRBCRDARA가 주어진 경우, 양쪽 모두에 포함되는 문자열에는 CA나 CADA나 ADABR이나 빈 문자열 등이 있다. 그중 가장 긴 것은 ADABR이며, 그 길이는 $5$이다. $2$개의 문자열 안에 포함되는 ADABR의 위치를 그림 $2\text{-}1$에 나타낸다.

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

그림 $2\text{-}1$: 예 $1$의 문자열 안에 나타나는 ADABR의 위치

예 $2$: 문자열로 UPWJCIRUCAXIIRGL과 SBQNYBSBZDFNEV가 주어진 경우, 양쪽 모두에 포함되는 문자열은 빈 문자열뿐이며, 그 길이는 $0$이다.

입력

입력은 $2$줄로 이루어지며, $1$번째 줄에 $1$번째 문자열이, $2$번째 줄에 $2$번째 문자열이 주어진다. 문자열은 영문 대문자로 이루어지며, 각 문자열의 길이는 $1$ 이상 $4\,000$ 이하이다.

채점용 데이터 중 배점의 $30\%$에 대해서는 각 문자열의 길이가 $1$ 이상 $50$ 이하이다.

출력

주어진 $2$개의 문자열 양쪽 모두에 포함되는 문자열 중 가장 긴 것의 길이만을 포함하는 $1$줄을 출력하라.

입출력 예제

예에 대응하는 입출력은 다음과 같다.

입력 예제 1

ABRACADABRA
ECADADABRBCRDARA

출력 예제 1

5

입력 예제 2

UPWJCIRUCAXIIRGL
SBQNYBSBZDFNEV

출력 예제 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.