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. windows安装AnyProxy 配合夜神模拟器抓包

    AnyProxy是阿里巴巴基于 Node.js 开发的一款开源代理服务器.做为中间代理服务器,它可以收集所有经过它的http请求流量(包括https明文内容):它提供了友好的web界面,便于直观的查看 ...

  2. JS----事件3

    一 事件对象(event):与特定事件相关且包含有关该事件详细信息的对象通过事件可以触发event对象的元素,鼠标的位置及状态,按下的键等等event对象只在事件发生的过程中才有效非IE浏览器里的ev ...

  3. spingboot @EnableScheduling

    springboot让开发更简单!springmvc中启用定时任务还得需要在xml中进行配置启用并且要配置扫描器,但是springboot只需要一个注解就可以. @EnableScheduling 无 ...

  4. [疯狂Java]JDBC:PreparedStatement预编译执行SQL语句

    1. SQL语句的执行过程——Statement直接执行的弊病: 1) SQL语句和编程语言一样,仅仅就会普通的文本字符串,首先数据库引擎无法识别这种文本字符串,而底层的CPU更不理解这些文本字符串( ...

  5. 九 configparser模块

    配置文件如下: # 注释1 ; 注释2 [section1] k1 = v1 k2:v2 user=egon age=18 is_admin=true salary=31 [section2] k1 ...

  6. Error:stray '\243' in program

    c++ 程序出现 Error:stray '\243' in program 错误 错误情况: 错误原因: 有不标准的 ASCII 字符出现,一般是中英文问题,比如 :or ;     , or ,等 ...

  7. poj 2553 缩点+染色+出度

    题目链接:https://vjudge.net/problem/POJ-2553 如果不会tarjan算法,推荐博客:https://blog.csdn.net/mengxiang000000/art ...

  8. nodejs中.npmrc文件的内容

    . nodejs安装后,使用npm安装模块的时候我出现了一个错误. getaddrinfo ENOTFOUND xxx 主要是这个配置文件的问题.搞不清楚.直接打开把文件内容删除变成 npmrc文件内 ...

  9. Bitmap byte[] InputStream Drawable 互转

    import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStrea ...

  10. Mycat性能调优指南

    本篇内容来自于网络 JVM调优: 内存占用分两部分:java堆内存+直接内存映射(DirectBuffer占用),建议堆内存 适度大小,直接映射内存尽可能大,两种一起占据操作系统的1/2-2/3的内存 ...