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
 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int a[+];
char temp[+];
bool check(const char t[],const char p[],int mid)
{
memset(temp,,sizeof(temp));
strcpy(temp,t); //拷贝到一个临时数组
for(int i=;i<=mid;i++) temp[a[i]-]=''; //把要划掉的那几个字母依次划掉
for(int i=,j=,temp_len=strlen(t),p_len=strlen(p);i<temp_len;i++){
if(temp[i] == p[j]) j++;
if(j == p_len) return true;
}
return false;
}
int main()
{
char t[+],p[+];
scanf("%s%s",t,p);
int t_len=strlen(t);
for(int i=;i<=t_len;i++) scanf("%d",&a[i]);
int st=,ed=t_len;
while(ed-st>)
{
int mid=st+(ed-st)/;
if(check(t,p,mid)) st=mid;
else ed=mid;
}
printf("%d\n",st);
}

开始的时候一直在test 10上RUNTIME_ERROR,一直找不出原因,刚开始以为二分那边有问题,换了网上AC的二分方式依然是这样,后来才发现开int数组a[]的大小时候

200000+5写成了20000+5……真是僵硬……看来预定义一个MAXN不是没有道理的……

codeforces 779D - String Game的更多相关文章

  1. CodeForces 779D. String Game(二分答案)

    题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...

  2. CodeForces - 779D String Game 常规二分

    题意:给你两个串,S2是S1 的一个子串(可以不连续).给你一个s1字符下标的一个排列,按照这个数列删数,问你最多删到第几个时S2仍是S1 的一个子串. 题解:二分删掉的数.判定函数很好写和单调性也可 ...

  3. CodeForces - 779D String Game(二分)

    Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...

  4. 【codeforces 779D】String Game

    [题目链接]:http://codeforces.com/contest/779/problem/D [题意] 给你一段操作序列; 按顺序依次删掉字符串1中相应位置的字符; 问你最多能按顺序删掉多少个 ...

  5. Codeforces 799D. String Game 二分

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

  6. 779D. String Game 二分 水

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

  7. Codeforces - 828C String Reconstruction —— 并查集find()函数

    题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...

  8. CodeForces 159c String Manipulation 1.0

    String Manipulation 1.0 Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on Cod ...

  9. Codeforces 710F String Set Quries

    题意 维护一个字符串的集合\(D\), 支持3种操作: 插入一个字符串\(s\) 删除一个字符串\(s\) 查询一个字符串\(s\)在\(D\)中作为子串出现的次数 强制在线 解法 AC自动机+二进制 ...

随机推荐

  1. 一些JavaScript基本函数

    1.document.write(”");为 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览 ...

  2. Tree Recovery(前序中序求后序)

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14640   Accepted: 9091 De ...

  3. JAVA内存泄露分析及解决

    一,问题产生     项目采用Tomcat6.0为服务器,数据库为mysql5.1,数据库持久层为hibernate3.0,以springMVC3.0为框架,项目开发完成后,上线前夕进行稳定性拷机,测 ...

  4. Greenplum-cc-web安装

    第一章 文档概述 1. 本安装手册描述适用于Greenplum4.0以上版本的安装Greenplum-cc-web操作 第二章 安装介质 针对Greenplum版本下载对应Greenplum-cc-w ...

  5. 使用dshow捕获摄像头图像

    #include "stdafx.h" #include <DShow.h> #include <Guiddef.h> #include <strmi ...

  6. RF-For循环使用

    场景1:

  7. Selenium 前进和后退

    我们平常使用浏览器时都有前进和后退功能, Selenium 也可以完成这个操作,它使用 back() 方法后退,使用 forward() 方法前进 from selenium import webdr ...

  8. React Native(三)——推送jpush-react-native

    瞬间,有种满血复活的赶脚…… 原因呢,就是熟悉了rn项目的套路:当老大问道,“推送功能看了还是没看呢?”的时候,虽然一直没有调试通,但还是不怯场的回答,“看了,按照网上说的也配了,但是还是用不了,不知 ...

  9. CoreData 多表 关联

    本文转载至 http://www.jianshu.com/p/e9f3b5e0cd19 1.概念简介 coreData中存在复杂的数据关系时,一张表难以满足需求,此时就需要了解使用coreData多表 ...

  10. Lua中的table构造式(table constructor)

    最简单的构造式就是一个空构造式{},用于创建一个空table. 构造式还可以用于初始化数组.例如,以下语句:days = {"Sunday", "Monday" ...