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

题意:给定两个字符串str1和str2,再给定一个strlen(str1)的整数序列,整数i表示从str1中删除位置处于i上的字符(即一次删除操作),删除后下标不变。问最多执行多少次删除操作,使剩下的字符串依然可以通过删除字符变成str2.

妈蛋啊,比赛时弄死没想到啊。。。注意力全放在了两个字符串上。。。结果序列才是关键啊。。。

思路:二分整数序列,然后找删除后是否合法。。。就这么简单。。。继续努力。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define N 200005 char str1[N],str2[N];
int num[N];
bool del[N]; int main()
{
scanf("%s%s",str1+,str2+);
int len1=strlen(str1+),len2=strlen(str2+);
for(int i=;i<=len1;i++)
scanf("%d",&num[i]);
int l=,r=len1,res=;
while(l<=r)
{
int mid=(l+r)>>;
memset(del,,sizeof(del));
for(int i=;i<=mid;i++)
del[num[i]]=;
int pos=;
for(int i=;i<=len1;i++)
{
if(del[i]==)
continue;
if(pos>len2)
break;
if(str1[i]==str2[pos])
pos++;
}
if(pos>len2)
{
res=mid;
l=mid+;
}
else
r=mid-;
}
printf("%d\n",res);
return ;
}

最新文章

  1. 使用python解析Json字符串-获取Json字符串关键字
  2. 定时器的应用---中断方式---让8个LED灯,左右各4个来回亮
  3. 支持Ajax跨域访问ASP.NET Web Api 2(Cors)的简单示例教程演示
  4. 使用plspl创建orcale作业
  5. Opencv——灰度直方图
  6. 2016032901 - ubuntu安装jdk
  7. ok6410驱动usb摄像头
  8. Bosch 英语面试准备分享
  9. .bat脚本将windows server 2008设置成ntp时间同步服务器
  10. 对[foreach]的浅究到发现[yield]
  11. iOS开发之instancetype
  12. NodeMCU入门(5):Docker Image 构建固件,开启SmartConfig
  13. Django缓存和内置信号
  14. mysql之行(记录)的详细操作
  15. Entity Framework学习初级篇1--EF基本概况《转》
  16. react与vue的对比
  17. Spring 通过Java代码装配bean
  18. 在centos7下安装svn
  19. Linux 命令安装bin文件
  20. python3-开发进阶 heapq模块(如何查找最大或最小的N个元素)

热门文章

  1. ExtJS ComboBox 下拉列表详细用法
  2. [办公自动化]excel工作簿内的表无法删除,单击右键无删除键
  3. 【codevs2011】【LNOI2013】最小距离之和
  4. shell 爬虫 从日志分析到数据采集与分析
  5. Cordova 开发 App
  6. iphone分辨率大全
  7. hdoj--1254--推箱子(bfs好题)
  8. CentOS查看CPU、内存、网络流量和磁盘 I/O【详细】
  9. 转贴:CSS伪类与CSS伪元素的区别及由来具体说明
  10. MySql 5.7 Archive 版本安装失败 解决过程