博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces_779_D.String Game_(二分)
阅读量:6852 次
发布时间:2019-06-26

本文共 3103 字,大约阅读时间需要 10 分钟。

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
#include
#include
#include
#include
#include
using namespace std;#define N 200005char str1[N],str2[N];int num[N];bool del[N];int main(){ scanf("%s%s",str1+1,str2+1); int len1=strlen(str1+1),len2=strlen(str2+1); for(int i=1;i<=len1;i++) scanf("%d",&num[i]); int l=1,r=len1,res=0; while(l<=r) { int mid=(l+r)>>1; memset(del,0,sizeof(del)); for(int i=1;i<=mid;i++) del[num[i]]=1; int pos=1; for(int i=1;i<=len1;i++) { if(del[i]==1) continue; if(pos>len2) break; if(str1[i]==str2[pos]) pos++; } if(pos>len2) { res=mid; l=mid+1; } else r=mid-1; } printf("%d\n",res); return 0;}

 

转载于:https://www.cnblogs.com/jasonlixuetao/p/6451832.html

你可能感兴趣的文章
字符串
查看>>
剖析非同质化代币ERC721-全面解析ERC721标准
查看>>
Python八荣八耻
查看>>
华硕网络硬盘服务出问题!遭到中间人攻击
查看>>
java电子商务系统源码 Spring MVC+mybatis+spring cloud+spring boot+spring security
查看>>
Java 实现 给Excel模板赋值(直接打开表格赋值或者用自定义了名称的单元格(一块区域)赋值)...
查看>>
DataLakeAnalytics: 解析IP地址对应的国家城市地址的能力
查看>>
20181120上课截图
查看>>
FastReport教程:如何从命令行使用报表设计器和查看器
查看>>
sed命令详解及运用
查看>>
一篇文章让你全部看懂!内存-java模型-jvm结构
查看>>
[转] Valgrind使用
查看>>
0023-HOSTS配置问题导致集群异常故障分析
查看>>
《软件开发工具》要点
查看>>
iOS开发 图形变换-做一个正方体
查看>>
jhead命令详解
查看>>
去你的lua和go,哥发现node.js原来才是最爱~
查看>>
OC中initialize方法和init方法的区别
查看>>
一些不可思议的小问题
查看>>
界面间传值
查看>>