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

Codeforces_779_D.String Game_(二分)的更多相关文章

  1. HDU5853 Jong Hyok and String(二分 + 后缀数组)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5853 Description Jong Hyok loves strings. One da ...

  2. acdream1116 Gao the string!(hash二分 or 后缀数组)

    问题套了一个斐波那契数,归根结底就是要求对于所有后缀s[i...n-1],所有前缀在其中出现的总次数.我一开始做的时候想了好久,后来看了别人的解法才恍然大悟.对于一个后缀来说 s[i...n-1]来说 ...

  3. Codeforces Round #402 D String Game(二分)

    [题目类型]二分答案 &题解: 只要你想到二分答案就不是难题了,但我当时确实是想不到. [时间复杂度]\(O(nlogn)\) &代码: #include <cstdio> ...

  4. Codeforces 799D. String Game 二分

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

  5. 779D. String Game 二分 水

    Link 题意: 给出两字符串$a$,$b$及一个序列,要求从前往后按照序列删掉$a$上的字符,问最少删多少使$b$串不为a的子串 思路: 限制低,直接二分答案,即二分序列位置,不断check即可. ...

  6. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

  7. Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)

    <题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的   Hamming ...

  8. Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)

    题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...

  9. 【CF676C】Vasya and String(二分查找,线性扫描尺取法)

    题意: 给出一个长度为n的字符串,只有字符'a'和'b'.最多能改变k个字符,即把'a'变成'b'或把'b'变成'a'. 问改变后的最长连续相同字符的字串长度为多少. 首先是二分查找,好想也好写 .. ...

随机推荐

  1. Pivotal Cloud Foundry安全原理解析

    云计算相关的技术差点儿都对传统网络架构和安全规则产生一定的冲击.Pivotal Cloud Foundry(PCF)也不例外,去年8月为了说服专业安全组织允许PaaS部署方案,特意为他们深入讲了下PC ...

  2. JQuery编程demo练习

    JQuery练习demo:     编敲代码,实现:     1.选中当中一列的复选框时,该复选框所在行的背景色高亮显示(黄色). 2.取消选中复选框时,所在行的背景色恢复. ============ ...

  3. python爬虫实践--求职Top10城市

    前言 从智联招聘爬取相关信息后,我们关心的是如何对内容进行分析,获取用用的信息.本次以上篇文章“5分钟掌握智联招聘网站爬取并保存到MongoDB数据库”中爬取的数据为基础,分析关键词为“python” ...

  4. 开发人员调试工具Chrome Workspace

    Workspace是个什么样的东西呢?他可以在开发人员工具中调试改动js或者css同一时候自己主动保存文件.可以避免开发人员在工具中调试好,再到编辑器中改动一次代码的反复操作,可以提高一定的效率 配置 ...

  5. 《炉石传说》架构设计赏析(4):Asset管理

    欢迎转载,请注明作者[燕良@游戏开发]及原文地址:http://blog.csdn.net/neil3d/article/details/39580197 另外.欢迎大家来我的QQ群交流各种游戏引擎相 ...

  6. Android Java包各种功能简述

    开发Android应用程序基本上使用的都是Java语言. 那么要想灵活的应用这一系统,就应当熟悉当中的Android Java包的各种功能. 一般的JAVA应用中.假设需用引用基础类库,通常须要使用例 ...

  7. cssTest

    html <!doctype html> <html> <head> <meta charset="utf-8"> <meta ...

  8. leetcode 690. Employee Importance——本质上就是tree的DFS和BFS

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  9. Linux 系统管理命令 - uptime - 显示系统的运行时间及负载

    命令详解 重要星级: ★★★☆☆ 功能说明: uptime 命令可以输出当前系统时间.系统开机到现在的运行时间.目前有多少用户在线和系统平均负载等信息 语法格式: uptime 说明: 直接执行 up ...

  10. E20171226-hm

    stack n.栈 heap  n.堆 backtracking 回溯法,後戻り storage  n. 贮存; 贮藏; 储藏处,仓库; 贮存器,蓄电(瓶); ストレージ