시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 6 | 6 | 6 | 100.000% |
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, which is specified by permutation of letters' indices of the word $t$: $a_1 \ldots a_{|t|}$ . Note that after removing one letter, the indices of other letters don't change. 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 file contain the words $t$ and $p$, respectively. Words are composed of lowercase letters of the Latin alphabet ($1 \le |p| < |t| \le 200 \, 000$) .
Next line contains a permutation $a_1 \ldots a_{|t|}$ of letter indices that specifies the order in which Nastya removes letters of $t$ ($1 \le a_i \le |t|$, all $a_i$ are distinct).
Print a single integer number, the maximum number of letters that Nastya can remove.
번호 | 배점 | 제한 |
---|---|---|
1 | 32 | $|t| \le 5000 $ |
2 | 36 | $|t| \le 2 \cdot 10^5$, all letters in $p$ are equal |
3 | 32 | $|t| \le 2 \cdot 10^5$ |
ababcba abb 5 3 4 1 7 6 2
3
Sequence of removing made by Nastya looks like this:
"ababcba
" $\rightarrow$ "abab
" $\rightarrow$ "cbaab
" $\rightarrow$ "abcbaab
" abcba
Nastya can not continue, because it is impossible to get word "abb
" from word "
".ababcba
So, Nastya will remove only three letters.
Contest > Innopolis Open in Informatics > Innopolis University Open, Olympiad in Informatics 2016-2017 A번