第一次写博客,一道水题,string game
2017-03-08 21:44
281 查看
D. String Game
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 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"
![](http://c<br/>4000<br/>odeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"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
output
input
output
Note
In the first sample test sequence of removing made by Nastya looks like this:
"ababcba"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"ababcba"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"ababcba"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"ababcba"
Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".
So, Nastya will remove only three letters.
由于题目理解错了,卡了好久,网上的答案也看不懂,看清了题目之后觉得不难
两个要点:
1.用到二分法对删除的那个数组进行二分
2.判断删除字符后的t中是否还含有p,代码:
for(i=1;i<=l1;i++)
b[i]=0;
for(i=1;i<=m;i++)
b[a[i]]=1;
for(i=1;i<=l1;i++)
{
if(!b[i]) continue;
if(s1[1]==s2[cnt]) cnt++;
if(cnt>l2) return 1;
}
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 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"
![](http://c<br/>4000<br/>odeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"nastya"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"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
Note
In the first sample test sequence of removing made by Nastya looks like this:
"ababcba"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"ababcba"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"ababcba"
![](http://codeforces.com/predownloaded/9e/58/9e58594e343ae98e6885aaa282186965f4b9653b.png)
"ababcba"
Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".
So, Nastya will remove only three letters.
由于题目理解错了,卡了好久,网上的答案也看不懂,看清了题目之后觉得不难
两个要点:
1.用到二分法对删除的那个数组进行二分
2.判断删除字符后的t中是否还含有p,代码:
for(i=1;i<=l1;i++)
b[i]=0;
for(i=1;i<=m;i++)
b[a[i]]=1;
for(i=1;i<=l1;i++)
{
if(!b[i]) continue;
if(s1[1]==s2[cnt]) cnt++;
if(cnt>l2) return 1;
}
相关文章推荐
- SRM 584 第一次玩TopCoder。。。只水题一道。。。
- SRM 584 第一次玩TopCoder。。。只水题一道。。。
- 广东工业大学第一次月赛的一道水题
- 三年第一次发博客
- 今天第一次在csdn博客上写文章。。。
- 第一次博客
- 找回密码,好久没上了第一次发博客好紧张啊
- 第一次通过写博客,来总结知识......
- 第一次写博客,不知道从何入手?
- 一道水题---lucas的数论
- 第一次开博客
- xdoj 1000(第一次写博客)
- 第一次来写博客 求个人气
- 第一次写CSDN的博客
- 第一次的博客
- 我的CSDN第一次博客
- 2014年7月1号 第一次在博客上记录生活中值得反思的事
- 第一次用CSDN的MarkDown写博客,遇到个奇葩问题!
- 改版第二周,迎来第一次喜悦——博客运营随笔10.9
- 水题先来一道,UVA6345