D. String Game
time limit per test:2 seconds
memory limit per test:512 megabytes
input:standard input
output:standard output

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 t: a1... 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.

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

题目链接:http://codeforces.com/contest/779/problem/D

题意:有2个字符串a,b。将a按照顺序删除,问a最多删除多少个字母后,依然包含b。保证数据有效,即一定有结果。

思路:二分。将a要删除的个数进行二分,每次二分后暴力寻找。时间复杂度为n*16.注意二分的姿势。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=2e5+;
char a[MAXN],b[MAXN];
int t[MAXN];
int main()
{
scanf("%s%s",a,b);
int n=strlen(a),m=strlen(b);
for(int i=; i<=n; i++)
{
int x;
scanf("%d",&x);
t[x-]=i;
}
int l=,r=n;
int ans=;
while(l<=r)
{
int mid=(l+r)/;
int i=,j=;
int flag=;
for(i=; i<n; i++)
{
if(t[i]<=mid) continue;
if(a[i]==b[j]) j++;
if(j==m) flag=;
}
if(flag==) l=mid+,ans=mid;
else r=mid-;
}
cout<<ans<<endl;
return ;
}

二分

Codeforces 799D. String Game 二分的更多相关文章

  1. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  2. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

  3. CodeForces 779D. String Game(二分答案)

    题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...

  4. Codeforces Round #402 D String Game(二分)

    [题目类型]二分答案 &题解: 只要你想到二分答案就不是难题了,但我当时确实是想不到. [时间复杂度]\(O(nlogn)\) &代码: #include <cstdio> ...

  5. CodeForces - 779D String Game 常规二分

    题意:给你两个串,S2是S1 的一个子串(可以不连续).给你一个s1字符下标的一个排列,按照这个数列删数,问你最多删到第几个时S2仍是S1 的一个子串. 题解:二分删掉的数.判定函数很好写和单调性也可 ...

  6. CodeForces - 779D String Game(二分)

    Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...

  7. Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)

    <题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的   Hamming ...

  8. Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)

    题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...

  9. codeforces 803D Magazine Ad(二分+贪心)

    Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...

随机推荐

  1. SPSS-判别分析

    判别分析 判别分析是一种有效的对个案进行分类分析的方法.和聚类分析不同的是,判别分析时组别的特征已知. 定义:判别分析先根据已知类别的事物的性质,利用某种技术建立函数式,然后对未知类别的新事物进 行判 ...

  2. 修改 Tomcat Connector运行模式 优化Tomcat运行性能

    omcat是一个小型的轻量级应用服务器,也是JavaEE开发人员最常用的服务器之一.不过,许多开发人员不知道的是,Tomcat Connector(Tomcat连接器)有bio.nio.apr三种运行 ...

  3. React DevTools

    [React DevTools] 在应用商店搜索安装.F12可打开.如果是react应用,在最右排会显示react标签. 参考:https://github.com/facebook/react-de ...

  4. Java 管道PipedInputStream PipedOutStream PipedReader PipedWriter

    java中的管道流(pipeStream)是一种特殊的流,用于在不同线程间直接传送数据.一个线程发送数据到输出管道,另外一个线程从输入管道中读取数据.通过使用管道,实现不同线程间的通信,而不必借助类似 ...

  5. jenkins动态参数插件Dynamic Parameter安装及简单使用

    插件安装: 1.先下载插件hpi文件到本地   jenkins插件下载地址 http://mirror.xmission.com/jenkins/plugins/ http://updates.jen ...

  6. Android Studio 中的FindBugs插件使用,轻松帮你发现Bug (转)

    在日常开发过程中难免会因为一时疏忽而留下一些Bug,这些Bug就是埋在程序里的定时炸弹,如果不能及时铲除就会导致程序的不稳定,异常或闪退的现象,从而导致用户的体验的下降.那么怎么才能找出这些埋在程序里 ...

  7. 利用反射绑定事件处理程序(C#)

    利用反射绑定事件处理程序(C#) 传统的写法:强类型的情况下 using System;using System.Collections.Generic;using System.Text; usin ...

  8. Ambertools15安装(详细)

    这篇博文专门讲述 Ambertools15的安装方法,尽管Ambertools16版本已经正是发行了,但两者在安装方式上没有任何区别.比较偏爱Ambertools15的原因主要还是在容量方面(230M ...

  9. ceph luminous 新功能之内置dashboard 之 mgr功能模块配置

    前言 ceph luminous版本新增加了很多有意思的功能,这个也是一个长期支持版本,所以这些新功能的特性还是很值得期待的,从底层的存储改造,消息方式的改变,以及一些之前未实现的功能的完成,都让ce ...

  10. LibreOJ 6281 数列分块入门5

    题目链接:https://loj.ac/problem/6281 参考博客:https://blog.csdn.net/qq_36038511/article/details/79725027 我一开 ...