博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces - 779D
阅读量:5147 次
发布时间:2019-06-13

本文共 2687 字,大约阅读时间需要 8 分钟。

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.

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. 

题意:当初看这个题看了快一小时了还是不理解,我。。。。

就是给了两个序列,序列a肯定包含序列b,然后给了一个删除序列,删除给定位置的字符,然后依照顺序删,看最多能删几个

思路:一开始肯定想的是直接遍历,然后用个标记数组直接记录哪个被删了,然后就T了

范围是 (1 ≤ |p| < |t| ≤ 200 000).然后我们想下,我们就是想求一个看能最多删几个的东西,去遍历可以得到,但是一般遍历能得到的东西,我们就可以想到二分,

如果删这么多满足的话,就继续往后二分,如果不行往前二分,时间复杂度就可以满足了

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int maxn = 1e6+100;char a[maxn];char b[maxn];char tmp[maxn];int c[maxn],n;bool slove(int pos){ strcpy(tmp,a); for(int i=0;i

 

 

要熟练掌握二分思想和满足二分的情况

刷多点题提高敏感度

转载于:https://www.cnblogs.com/Lis-/p/9240929.html

你可能感兴趣的文章
Mac搭建Java开发环境
查看>>
C#尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
查看>>
#231-D: declaration is not visible outside of function
查看>>
matlab程序性能优化与混合编程技术介绍
查看>>
推荐学习笔记-协同过滤2
查看>>
英语语法
查看>>
C++标准库简介(转)
查看>>
Linux从入门到精通——控制服务
查看>>
android图片下载问题
查看>>
高并发场景下System.currentTimeMillis()的性能优化
查看>>
OpenCV&Qt学习之三——图像的初步处理
查看>>
常用命令备查
查看>>
大道至简(第四章)读后感
查看>>
SDN第四次作业
查看>>
idea连接服务器上传jar并运行
查看>>
oracle高级分组
查看>>
django--->form表单
查看>>
获取网页源代码
查看>>
译]JavaScript规范-葵花宝典
查看>>
【linux】——Linux tar打包命令
查看>>