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.

题目链接:D. String Game

简单二分题,二分答案,每一次check一下是否能组成 t串即可

代码:

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int N=200010;
char p[N],t[N];
int arr[N]; int lp,lt;
bitset<N>mov; inline bool check(int cnt)
{
mov.reset();
int i;
for (i=1; i<=cnt; ++i)
mov[arr[i]]=1;
int res=1;
for (i=1; i<=lp; ++i)
{
if(!mov[i]&&p[i]==t[res])
{
++res;
if(res>lt)
return true;
}
}
return false;
}
int main(void)
{
int i;
while (~scanf("%s",p+1))
{
scanf("%s",t+1);
lp=strlen(p+1);
lt=strlen(t+1);
for (i=1; i<=lp; ++i)
scanf("%d",&arr[i]);
int L=0,R=lp;
int ans=0;
while (L<=R)
{
int mid=MID(L,R);
if(check(mid))
{
ans=mid;
L=mid+1;
}
else
R=mid-1;
}
printf("%d\n",ans);
}
return 0;
}

最新文章

  1. github如何查看提交历史呢
  2. 苹果iOS强制HTTPS迫在眉睫,距离2017年只剩1天,准备好了么?
  3. mysql中,ENCODE警告---Warning Code : 1287
  4. 基于天天动听API开发在线音乐查询网站
  5. memcached学习笔记5--socke操作memcached 缓存系统
  6. sublime 修改Xdebug插件快捷键
  7. C#列表顺序替换思想
  8. python绝技 — 用Scapy测试无线网卡的嗅探功能
  9. (简单) HUST 1017 Exact cover , DLX+精确覆盖。
  10. Java scheduled executor
  11. Spark 作业调度相关术语
  12. Swift 结构体的使用
  13. vue-基于elementui换肤
  14. [Leetcode 15]三数之和 3 Sum
  15. Windows系统环境下创建mysql主从数据库方法(双向主从复制)
  16. (转) VS2010 Addins 外接程序(插件)开发
  17. ES6-Object‘s Extends
  18. React:组件的生命周期
  19. openvpn-在Linux中安装和配置OpenVPN Server的最简便方法!(转)
  20. Django 中文显示

热门文章

  1. iOS 集成支付宝过程中 我遇到的一些坑,请大家注意啦(ALI69错误,ALI64错误)
  2. RobotFramework:钉钉扫码登录UI自动化
  3. selective search生成.mat文件
  4. pyqt4 python2.7 中文乱码的解决方法
  5. js字符串的使用
  6. 基于django的个人博客网站建立(一)
  7. pandas知识点(数据结构)
  8. POJ3436------ACM Computer Factory
  9. 运维Python面试题
  10. SXCPC2018 nucoj2004 国王的怪癖