博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
778A String Game
阅读量:5024 次
发布时间:2019-06-12

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

A. 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 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.

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.

 

1 #include 
2 #include
3 using namespace std; 4 5 const int N = 2e5 + 10; 6 char str1[N], str2[N]; 7 int len1, len2; 8 int vis[N], num[N]; 9 10 bool judge(int pos){
//判断str1中是否含有str211 memset(vis,0,sizeof(vis));12 for(int i = 0; i < pos; i++){13 vis[num[i] - 1] = 1;// 标记被删除元素14 }15 int ans = 0;16 for(int i = 0; i < len1; i++){17 if(vis[i] == 0 && (str2[ans] == str1[i]))18 ans++;19 if(ans >= len2)//说明str1 中含有 str220 return true;21 }22 return false;23 }24 25 int main(){26 int ans;27 cin >> str1 >> str2;28 len1 = strlen(str1);29 len2 = strlen(str2);30 for(int i = 0; i < len1; i++){31 cin >> num[i];32 }33 int mid;34 int l = 0, r = len1 - 1;35 while(l <= r){
//对 num[] 二分查找num[]中最后一个删除后符合的元素下标36 mid = (l + r) >> 1;//即mid = (l + r) / 2;37 if(judge(mid)){38 l = mid + 1;39 ans = mid;40 }41 else {42 r = mid - 1;43 }44 }45 cout << ans << endl;46 }

 

转载于:https://www.cnblogs.com/jxust-jiege666/p/6641059.html

你可能感兴趣的文章
为什么JS动态生成的input标签在后台有时候没法获取到
查看>>
20189210 移动开发平台第六周作业
查看>>
java之hibernate之基于外键的双向一对一关联映射
查看>>
rxjs一句话描述一个操作符(1)
查看>>
第一次独立上手多线程高并发的项目的心路历程
查看>>
ServiceStack 介绍
查看>>
Centos7下载和安装教程
查看>>
无谓的通宵加班之后的思索
查看>>
S1的小成果:MyKTV系统
查看>>
从setting文件导包
查看>>
编写一个函数isMerge,判断一个字符串str是否可以由其他两个字符串part1和part2“组合”而成...
查看>>
union和union all
查看>>
Github 开源:使用控制器操作 WinForm/WPF 控件( Sheng.Winform.Controls.Controller)
查看>>
PMD使用提醒
查看>>
Codeforces 887D Ratings and Reality Shows
查看>>
论文《A Generative Entity-Mention Model for Linking Entities with Knowledge Base》
查看>>
CentOS 6.7编译安装PHP 5.6
查看>>
Linux记录-salt分析
查看>>
Android Studio默认快捷键
查看>>
发布开源库到JCenter所遇到的一些问题记录
查看>>