#TP0000065. Xóa đoạn con dài nhất (Remove the Substring – Hard Version)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xóa đoạn con dài nhất (Remove the Substring – Hard Version)
Remove the Substring (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given lowercase strings and , it is guaranteed that is a subsequence of . You may remove one contiguous substring of and concatenate the remaining characters in their original order. Find the maximum number of characters removable while preserving as a subsequence. Removing zero characters is allowed.
Input
- The first line contains the string .
- The second line contains the string .
Output
Print the maximum length of a removable contiguous substring.
Subtasks
- Subtask 1 (20 points): ; both strings contain only lowercase Latin letters; is a subsequence of .
- Subtask 2 (30 points): ; both strings contain only lowercase Latin letters; is a subsequence of .
- Subtask 3 (50 points): ; both strings contain only lowercase Latin letters; is a subsequence of .
Examples
Input
bbaba
bb
Output
3
Explanation
For bbaba and bb, remove positions through , namely aba. The remaining string is bb, which still contains as a subsequence. This removes characters. Any valid result must retain at least the two characters of , so from a string of length one cannot remove more than . Thus the answer is 3.