QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 64 MB Total points: 20

#23774. 共通部分文字列

Statistics

問題

$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.