【codeforce】补题 D1. Remove the Substring (easy version)

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|s1s2…sl−1sr+1sr+2…s|s|−1s|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.

Input

The first line of the input contains one string ss consisting of at least 11 and at most 200200 lowercase Latin letters.

The second line of the input contains one string tt consisting of at least 11 and at most 200200 lowercase Latin letters.

It is guaranteed that tt is a subsequence of ss.

Output

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

Examples

input

Copy

bbaba
bb

output

Copy

3

input

Copy

baaba
ab

output

Copy

2

input

Copy

abcde
abcde

output

Copy

0

input

Copy

asdfasdf
fasd

output

Copy

3

 错误做法:找第二个串的字符在第一个串里面的下标,记录下来,然后枚举找最大长度。

错因:找不到最大的距离,每次记录的位置不符合要求。以下是错误代码:

#include<bits/stdc++.h>
using namespace std;
map<char,int> mp;
int a[50000],b[3];
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    if(s1==s2) {puts("0");return 0;}
    int k=1;
    int maxn=-0x3f3f3f3f,cnt=0;
    a[1]=s1.find(s2[0])+1;
    for(int i=1;i<s2.size();i++)
    {
        for(int j=0;j<s1.size();j++)
        {
            if(s1[j]==s2[i]&&j+1>a[k]){
                a[++k]=j+1;/*i++*/
                break;
            }
        }
        /*while(s1.find(s2[i])+1>a[k]){
            a[++k]=s1.find(s2[i])+1;i++;
        }*/
    }
    b[1]=a[1]-1;
    b[2]=s1.size()-a[k];
    for(int i=1;i<k;i++)
    {
        if(a[i+1]-a[i]-1>maxn) maxn=a[i+1]-a[i]-1;
    }
    int ans=max(b[1],max(b[2],maxn));
    cout<<ans;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值