A10784 | String Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
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|<=200000$ ). 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).
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).
输出格式
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.
"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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted