Codeforces Round #402 D(二分)
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.
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).
Print a single integer number, the maximum number of letters that Nastya can remove.
ababcba
abb
5 3 4 1 7 6 2
3
bbbabb
bb
1 6 3 4 2 5
4
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.
a b两个字符串
我们只需要对答案而分 判断a是否包含b
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
#include<string>
#define eps 0.000000001
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int N=+;
char str[N],b[N];
int a[N];
int vis[N];
int len,len1;
int judge(int x){
for(int i=;i<len;i++)vis[i]=;
for(int i=;i<x;i++)vis[a[i]-]=;
int ans=;
for(int i=;i<len;i++){
if(vis[i]==&&str[i]==b[ans])ans++;
if(ans>=len1)return ;
}
return ;
}
int main(){
while(cin>>str){
cin>>b;
len=strlen(str);
len1=strlen(b);
for(int i=;i<len;i++)cin>>a[i];
int l=;
int r=len-;
int mid;
int ans;
while(l<=r){
mid=(l+r)>>;
if(judge(mid)){
l=mid+;
ans=mid;
}
else
r=mid-;
}
cout<<ans<<endl;
}
}
最新文章
- 【linux】学习5
- Javascript中大括号“{}”的多义性
- Nginx 性能优化
- MySQL数据库最大连接数
- IOS应用程序多语言本地化解决方案
- CI 笔记7,easyui 异步加载
- YII2 运行概述(Overview)
- java核心技术面试整理
- [C++学习历程]基础部分 C++中的指针数组和结构
- wf 2017A
- 初涉FlaskWeb开发----基础篇
- ubuntu下利用docker搭建gitloab手记
- 20135327郭皓--Linux内核分析第四周 扒开系统调用的三层皮(上)
- UNIX环境编程学习笔记(28)——多线程编程(三):线程的取消
- 上产使用MQ的三点注意
- 适合自己的adblock过滤列表
- Scala并发编程模型AKKA
- Python setattr() 函数
- 一种很有意思的数据结构:Bitmap
- 全球数字货币交易所TOP20安全性评级报告