CF1203D2.Remove the Substring (hard version)

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The only difference between easy and hard versions is the length of the string.

You are given a string ss and a string tt, both consisting only of lowercase Latin letters. It is guaranteed that tt can be obtained from ss by removing some (possibly, zero) number of characters (not necessary contiguous) from ss without changing order of remaining characters (in other words, it is guaranteed that tt is a subsequence of ss).

For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".

You want to remove some substring (contiguous subsequence) from ss of maximum possible length such that after removing this substring tt will remain a subsequence of ss.

If you want to remove the substring s[l;r]s[l;r] then the string ss will be transformed to s1s2…sl−1sr+1sr+2…s∣s∣−1s∣s∣s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|} (where ∣s∣|s| is the length of ss).

Your task is to find the maximum possible length of the substring you can remove so that tt is still a subsequence of ss.

简单版本与困难版本的唯一区别在于字符串的长度。

给你两个字符串 ss 和 tt,它们均由小写拉丁字母组成。保证 tt 可通过从 ss 中删除若干(可能为零)个字符(不必连续)并保持剩余字符的相对顺序得到(即:保证 tt 是 ss 的一个子序列)。

例如,字符串 "test"、"tst"、"tt"、"et" 和 "" 都是 "test" 的子序列;但 "tset"、"se" 和 "contest" 不是 "test" 的子序列。

你希望从 ss 中删除一个长度尽可能大的子串(即一段连续的子序列),使得删除后 tt 仍然是 ss 的子序列。

若你要删除子串 s[l;r]s[l;r],则字符串 ss 将变为 s1s2…sl−1sr+1sr+2…s∣s∣−1s∣s∣s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}(其中 ∣s∣|s| 表示 ss 的长度)。

你的任务是:求出可删除的子串的最大可能长度,使得 tt 在删除后仍为 ss 的子序列。

输入格式

The first line of the input contains one string ss consisting of at least 11 and at most 2⋅1052 \cdot 10^5 lowercase Latin letters.

The second line of the input contains one string tt consisting of at least 11 and at most 2⋅1052 \cdot 10^5 lowercase Latin letters.

It is guaranteed that tt is a subsequence of ss.

输入的第一行包含一个字符串 ss,由至少 11 个、至多 2⋅1052 \cdot 10^5 个小写拉丁字母组成。

输入的第二行包含一个字符串 tt,由至少 11 个、至多 2⋅1052 \cdot 10^5 个小写拉丁字母组成。

保证 tt 是 ss 的一个子序列。

输出格式

Print one integer — the maximum possible length of the substring you can remove so that tt is still a subsequence of ss.

输出一个整数——你可以删除的子串的最大可能长度,使得 tt 仍然是 ss 的子序列。

输入输出样例

  • 输入#1

    bbaba
    bb

    输出#1

    3
  • 输入#2

    baaba
    ab

    输出#2

    2
  • 输入#3

    abcde
    abcde

    输出#3

    0
  • 输入#4

    asdfasdf
    fasd

    输出#4

    3

输入解题思路,AI测评打分。不知道怎么写?

首页