国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Codeforces Round #402 (Div. 1) A. String Game

2019-11-06 06:23:10
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
A. String Gametime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard 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.

Examplesinput
ababcbaabb5 3 4 1 7 6 2output
3input
bbbabbbb1 6 3 4 2 5output
4Note

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.

思路:將所給依次取字符序列下標(biāo)進(jìn)行二分,注意最終條件,舉例后可推知最終位置為 (l+r)/ 2;

#include <bits/stdc++.h>using namespace std;const int MAXN = 200000 + 7;int index[MAXN], len1, len2;string str1, str2;bool isValid(int pos) {        string str = str1;        for(int i = 0; i < pos; ++i) {                str[index[i]-1] = '0';        }        int cnt = 0;        for(int i = 0; i < len1; ++i) {                if(str[i] == str2[cnt]) {                        cnt++;                        if(cnt == len2) return true;                }        }        return cnt == len2 ? true : false;}int main() {        ios::sync_with_stdio(false);        cin >> str1 >> str2;        len1 = str1.length(), len2 = str2.length();        for(int i = 0; i < len1; ++i) {                cin >> index[i];        }        int l = 0, r = len1, mid;        while(r >= l) {                mid = (l + r) / 2;                if(isValid(mid)) {                        l = mid + 1;                }                else                {                        r = mid - 1;                }        }        cout << (l+r) / 2 << endl;        return 0;}


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜川县| 都安| 榕江县| 桂平市| 曲阜市| 定兴县| 土默特右旗| 甘南县| 凉城县| 舞钢市| 忻城县| 海原县| 电白县| 左贡县| 威信县| 当雄县| 鹤峰县| 习水县| 蒙山县| 南乐县| 临夏市| 辉南县| 永新县| 抚松县| 常州市| 萨嘎县| 大悟县| 巫溪县| 山东| 农安县| 灯塔市| 黑龙江省| 卫辉市| 万安县| 治多县| 黄骅市| 郓城县| 平武县| 鹿邑县| 德庆县| 常熟市|