D. String Game

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.

Input

ababcba
abb

Output


Input

bbbabb
bb

Output


题意:给你一段操作序列;按顺序依次删掉字符串1中相应位置的字符;问你最多能按顺序删掉多少个字符;使得s2是剩下的字符构成的字符串的子列;

 思路:二分答案+暴力

AC代码:

 #include <bits/stdc++.h>
using namespace std; const int N = 2e5 + ;
char s1[N], s2[N];
bool vis[N];
int a[N], n, l2;
bool ok(){
for (int i = , j = ; i <= n && j <= l2; i++){
if (!vis[i]) continue;
if (s1[i] == s2[j]){
j++;
if (j > l2)
return true;
}
}
return false;
}
int main(){
scanf("%s", s1 + );
n = strlen(s1 + );
scanf("%s", s2 + );
l2 = strlen(s2 + );
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int l = , r = n, ans = ;
while (l <= r){
int m = (l + r) >> ;
for(int i=;i<=n;i++)
vis[a[i]] = true;
for(int i=;i<=m;i++)
vis[a[i]] = false;
if (ok()){
ans = m;
l = m + ;
}
else
r = m - ;
}
printf("%d\n", ans);
return ;
}

最新文章

  1. golang DynamoDB sdk AccessDeniedException
  2. 给div加上背景图片
  3. CSS 盒子模型概述
  4. 你知道require是什么吗?
  5. MYSQL索引失效的各种情形总结
  6. go编写简单的web服务器
  7. Nexus中自定义私服,每个项目都用独立的工厂,仓库
  8. Codeforces Round #136 (Div. 1)C. Little Elephant and Shifts multiset
  9. (Android Studio)添加按钮以及权重问题
  10. 算法 后减前最大值,zt
  11. [置顶] Android系统访问控制之Smack安全策略设计与实现
  12. Dalvik虚拟机JNI方法的注册过程分析
  13. Webpack 2 视频教程 009 - 配置 ESLint 实现代码规范自动测试 (上)
  14. MongoDB 查询分析
  15. android升级后错误:Unable to execute dex: java.nio.BufferOverflowException.Check
  16. 【原创】大数据基础之Impala(3)部分调优
  17. 需要转义的java字符(转)
  18. SoftWater——SDN+UnderWater系列论文一
  19. Centos安装Oracle及问题处理
  20. 1.揭开消息中间件RabbitMQ的神秘面纱

热门文章

  1. 【AtCoder】AGC001
  2. python 安装virtualenv和wxPython
  3. 【AC自动机】Censoring
  4. Invalid default value for &#39;time&#39;
  5. C#签名验签帮助类
  6. C++单链表类(带头结点)
  7. __imp__SetupDiDestroyDeviceInfoList
  8. Python诞生以来意义菜谱
  9. 利用FastReport直接生成条码
  10. linux——实际工作中如何使用linux