CF778A.String Game

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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: _a_1... 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.

小娜斯佳有一个爱好:她喜欢从一个单词中删除一些字母,从而得到另一个单词。但由于她年纪太小,这项任务对她来说相当困难,因此她的哥哥谢尔盖总是帮助她。

谢尔盖给娜斯佳一个单词 tt,并希望从中得到单词 pp。娜斯佳按特定顺序(依次、严格按此顺序)删除字母,该顺序由单词 tt 的字母下标的一个排列 a1…a∣t∣a_1 \dots a_{|t|} 给出。我们用 ∣x∣|x| 表示单词 xx 的长度。注意:每次删除一个字母后,其余字母的下标保持不变。例如,若 t=“nastya”t = \text{``nastya''} 且 a=[4, 1, 5, 3, 2, 6]a = [4,\,1,\,5,\,3,\,2,\,6],则删除过程生成如下单词序列:

“nastya” “nastya” “nastya” “nastya” “nastya” “nastya” “nastya”。

谢尔盖知道这个排列。他的目标是在某个时刻阻止妹妹继续操作,然后由他自己完成后续的删除操作,最终得到单词 pp。由于娜斯佳很喜欢这项活动,谢尔盖希望尽可能晚地阻止她。你的任务是确定:在谢尔盖阻止她之前,娜斯佳最多可以删除多少个字母。

题目保证:单词 pp 可通过从单词 tt 中删去若干字母而得到。

输入格式

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 _a_1, _a_2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a__i ≤ |t|, all a__i are distinct).

输入的第一行和第二行分别包含单词 tt 和 pp。单词由拉丁字母小写字母组成(1 ≤ ∣p∣ < ∣t∣ ≤ 200 0001 ≤ |p| < |t| ≤ 200\,000)。保证单词 pp 可通过从单词 tt 中删除若干字母得到。

下一行包含一个排列 a1, a2, …, a∣t∣a_1,\,a_2,\,\dots,\,a_{|t|},表示娜斯佳从 tt 中删去字母的顺序(1 ≤ ai ≤ ∣t∣1 ≤ a_i ≤ |t|,所有 aia_i 互不相同)。

输出格式

Print a single integer number, the maximum number of letters that Nastya can remove.

输出一个整数,表示娜斯佳最多可以删除的字母数量。

输入输出样例

  • 输入#1

    ababcba
    abb
    5 3 4 1 7 6 2

    输出#1

    3
  • 输入#2

    bbbabb
    bb
    1 6 3 4 2 5

    输出#2

    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.

在第一个样例测试中,Nastya 执行的删除操作序列为:

"ababcba" "ababcba" "ababcba" "ababcba"

Nastya 无法继续操作,因为无法从字符串 "ababcba" 中得到字符串 "abb"。

因此,Nastya 仅能删除三个字母。

输入解题思路,AI测评打分。不知道怎么写?

首页