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

 #include <iostream>
#include <cstring>
using namespace std; const int N = 2e5 + ;
char str1[N], str2[N];
int len1, len2;
int vis[N], num[N]; bool judge(int pos){//判断str1中是否含有str2
memset(vis,,sizeof(vis));
for(int i = ; i < pos; i++){
vis[num[i] - ] = ;// 标记被删除元素
}
int ans = ;
for(int i = ; i < len1; i++){
if(vis[i] == && (str2[ans] == str1[i]))
ans++;
if(ans >= len2)//说明str1 中含有 str2
return true;
}
return false;
} int main(){
int ans;
cin >> str1 >> str2;
len1 = strlen(str1);
len2 = strlen(str2);
for(int i = ; i < len1; i++){
cin >> num[i];
}
int mid;
int l = , r = len1 - ;
while(l <= r){//对 num[] 二分查找num[]中最后一个删除后符合的元素下标
mid = (l + r) >> ;//即mid = (l + r) / 2;
if(judge(mid)){
l = mid + ;
ans = mid;
}
else {
r = mid - ;
}
}
cout << ans << endl;
}

778A String Game的更多相关文章

  1. Codeforces 778A:String Game(二分暴力)

    http://codeforces.com/problemset/problem/778/A 题意:给出字符串s和字符串p,还有n个位置,每一个位置代表删除s串中的第i个字符,问最多可以删除多少个字符 ...

  2. 透过WinDBG的视角看String

    摘要 : 最近在博客园里面看到有人在讨论 C# String的一些特性. 大部分情况下是从CODING的角度来讨论String. 本人觉得非常好奇, 在运行时态, String是如何与这些特性联系上的 ...

  3. JavaScript String对象

    本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...

  4. ElasticSearch 5学习(9)——映射和分析(string类型废弃)

    在ElasticSearch中,存入文档的内容类似于传统数据每个字段一样,都会有一个指定的属性,为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成字符串值,Elasticsearc ...

  5. [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密

    string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...

  6. js报错: Uncaught RangeError: Invalid string length

    在ajax请求后得到的json数据,遍历的时候chrome控制台报这个错误:Uncaught RangeError: Invalid string length,在stackoverflow查找答案时 ...

  7. c# 字符串连接使用“+”和string.format格式化两种方式

    参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...

  8. 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed

    之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...

  9. JavaScript中String对象的方法介绍

    1.字符方法 1.1 charAt() 方法,返回字符串中指定位置的字符. var question = "Do you like JavaScript?"; alert(ques ...

随机推荐

  1. 将一个dropdownlist从一个div复制到另一个div

    <select id="dropdwon1"> <option value=">Item1</option> <option v ...

  2. Oracle Error

    1. TNS:listener does not currently know of service requested in connect descriptor 数据库连接出错

  3. CSS 颜色术语

    术语和概念在理科学习非常重要.CSS中有些关键的术语的. 对比度 对比度是指前景色和背景色之间的差距.当前景颜色和背景色之间的对比度较低时,文本就难以阅读.这对视觉障碍或色盲来说更严重. 透明度 透明 ...

  4. apicloud监听返回键(安卓试过)

    下面监听写在apiready里面 api.addEventListener({ //使用下方函数此处好像失效了 name: 'keyback' }, function(ret, err) { aler ...

  5. 04_web基础(五)之cookie与session

    29.Http协议无记忆带来的问题 什么是会话:可简单理解为:用户开一个浏览器,访问某一个web站点,在这个站点点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一次会话. 在一 ...

  6. 【C++】正则表达式引擎学习心得

    最近参照一些资料实现了一个非常简易的正则表达式引擎,支持基本的正则语法 | + * ()等. 实现思路是最基本的:正则式->AST->NFA->DFA. 以下是具体步骤: 一. 正则 ...

  7. BASE64Encoder/BASE64Decoder(转)

    eclipse中解除jdk的访问限制(以BASE64Encoder/BASE64Decoder为例) 解除访问限制前: 所以需要添加一个访问许可,步骤如下: 1.选择所在项目,右击鼠标选择Build ...

  8. 有人说,即使没有JavaScript,你也可以做网页。在纯HTML

    有人说,即使没有JavaScript,你也可以做网页.在纯HTML +服务器端语言理论中也可以完成所有功能,那么,为什么以及在哪里存在JavaScript?   JS,全称JavaScript   在 ...

  9. 获取txt里面的内容

    import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.Event; var txtLoad:URLL ...

  10. NumPy 字符串函数

    NumPy 字符串函数 以下函数用于对 dtype 为 numpy.string_ 或 numpy.unicode_ 的数组执行向量化字符串操作. 它们基于 Python 内置库中的标准字符串函数. ...