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 ;
}

Codeforces Round #402 (Div. 2) D题 【字符串二分答案+暴力】的更多相关文章

  1. Codeforces Round #211 (Div. 2) D题(二分,贪心)解题报告

    ---恢复内容开始--- 题目地址 简要题意: n个小伙子一起去买自行车,他们有每个人都带了一些钱,并且有公有的一笔梦想启动资金,可以分配给任何小伙子任何数值,当然分配权在我们的手中.现在给出m辆自行 ...

  2. Codeforces Round #352 (Div. 2) D. Robin Hood (二分答案)

    题目链接:http://codeforces.com/contest/672/problem/D 有n个人,k个操作,每个人有a[i]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差 ...

  3. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  4. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  5. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  6. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  7. Codeforces Round #402 (Div. 2) D. String Game(二分答案水题)

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  8. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  9. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

随机推荐

  1. Spark Scala当中reduceByKey的用法

    [学习笔记] /*reduceByKey(function)reduceByKey就是对元素为KV对的RDD中Key相同的元素的Value进行function的reduce操作(如前所述),因此,Ke ...

  2. js图片压缩上传

    最近公司的移动产品相约app要做一次活动,涉及到图片上传,图片又不能太大,不然用户体验太差,必须先压缩再上传,所以用到了html5的canvas和FileReader,代码先上,小弟前端经验不足,代码 ...

  3. 码云以及Git的使用

    码云以及Git的使用 码云就是一个远程管理的仓库,Git是用来上传和下载数据的工具. 首先访问网站 https://gitee.com/ 进行注册 注册完成后,进入如下页面 点击新建仓库 设置自己的仓 ...

  4. 笔记-4:python组合数据类型

    1.字符串(str) 字符串是字符的序列表示, 根据字符串的内容多少分为单行字符串和多行字符串. 单行字符串可以由一对单引号(') 或双引号(")作为边界来表示, 单引号和双引号作用相同. ...

  5. MyBatis学习存档(4)——进行CRUD操作

    使用MyBatis进行数据库的CRUD操作有2种方式:一种如之前所说的接口+xml,而另一种是通过对接口上的方法加注解(@Select @Insert @Delete @Update) 但是通常情况下 ...

  6. Linux:删除一个目录下的所有文件,但保留一个指定文件

    面试题:删除一个目录下的所有文件,但保留一个指定文件 解答: 假设这个目录是/xx/,里面有file1,file2,file3..file10  十个文件 [root@oldboy xx]# touc ...

  7. MVC全局过滤器

    Asp.NET MVC4中的全局过滤器,可以对整个项目进行全局监控. 新建一个MVC4项目,可以在global.asax文件中看到如下代码:  FilterConfig.RegisterGlobalF ...

  8. MUI 跨域请求web api

    由于刚接触MUI框架,所以在跨域问题上花了一点时间.希望我的方式能帮你少走点弯路(大神就直接过里吧)! 首先,遇到这个问题,各种百度.其中说法最多的是将mui,js文件里的 setHeader('X- ...

  9. 手写走通HTTP server 第三版本

    后台 后端 服务端 功能:逻辑处理 算法处理    磁盘交互(数据库   静态文件处理) 要求:健壮性,安全性 并发性能和处理速度 架构合理便于维护扩展 网站后端 httpserver + WebFr ...

  10. BootStrap【三、组件】

    特有标签属性 role 用于浏览器识别 aria-label 用于浏览器识别 tabIndex 用于浏览器识别 data- 自定义数据属性 图标 直接引用官方图标库中的class 官方图标库 Demo ...