• String Game


    Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.

    Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word ta1... a|t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya"  "nastya"  "nastya"  "nastya"  "nastya"  "nastya"  "nastya".

    Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.

    It is guaranteed that the word p can be obtained by removing the letters from word t.

    Input

    The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t.

    Next line contains a permutation a1, a2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ ai ≤ |t|, all ai are distinct).

    Output

    Print a single integer number, the maximum number of letters that Nastya can remove.

    Example

    Input
    ababcba
    abb
    5 3 4 1 7 6 2
    Output
    3
    Input
    bbbabb
    bb
    1 6 3 4 2 5
    Output
    4

    Note

    In the first sample test sequence of removing made by Nastya looks like this:

    "ababcba"  "ababcba"  "ababcba"  "ababcba"

    Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".

    So, Nastya will remove only three letters.

    //大概意思就是给你个字符串,然后给你个比对的串,给你几个位置,依次从这几个位置删除第一个串中的字符,对比删除后字符2是否是字符1的子串,输出最多删除的次数。

    #include<bits/stdc++.h>
    using namespace std;
    
    char t[200010],p[200010];
    int flag[200010],a[200010],n,m;
    bool ceshi(int x);
    int main()
        {
            int l,r,mid;
            scanf("%s%s",t+1,p+1);
                n=strlen(t+1);
                m=strlen(p+1);
            for (int i=1;i<=n;i++)
                cin>>a[i];
            l=0,r=n; while (l<r)
            {
                mid=(l+r+1)/2;
                if (ceshi(mid)) l=mid;
                else r=mid-1;
                }
                cout<<l;
                }
    
    bool ceshi(int x) {
        int j=1;
        for (int i=1;i<=x;i++)
            flag[a[i]]=0;
        for (int i=x+1;i<=n;i++)
            flag[a[i]]=1;
        for (int i=1;i<=n&&j<=m;i++)
            if (flag[i]&&t[i]==p[j]) j++;
        return j==m+1;
        }
  • 相关阅读:
    github release 文件下载贼慢,干脆失败的解决方法
    windows 下sublime text 3 配置python 环境详解
    Ubuntu下安装并使用sublime text 3(建议:先安装Package controls 后在看本教程,否则可能会安装不了)
    将博客搬至CSDN
    signalr core客户端通过ssl连接服务的方式
    解决html导出pdf中文乱码问题的正确姿势
    记一次asp.net core 在iis上运行抛出502.5错误
    Elasticsearch 集群搭建
    bower私服部署
    体验Code::Blocks下的Windows GUI编程(32 bit and 64 bit)
  • 原文地址:https://www.cnblogs.com/upstart/p/6558638.html
Copyright © 2020-2023  润新知