思路:直接二分答案判断是否满足条件即可,下面给代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<functional>
typedef long long LL;
using namespace std;
#define maxn 200005
#define ll l,mid,now<<1
#define rr mid+1,r,now<<1|1
#define lson l1,mid,l2,r2,now<<1
#define rson mid+1,r1,l2,r2,now<<1|1
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;
char s1[maxn], s2[maxn];
int a[maxn], len1, len2, vis[maxn];
bool check(int nowlen){
int pos1 = 0, pos2 = 0;
memset(vis, 0, sizeof(vis));
for (int i = 0; i < nowlen; i++)
vis[a[i] - 1] = 1;
while (pos1 < len1&&vis[pos1])
pos1++;
while (pos2 < len2&&pos1 < len1){
if (s2[pos2] == s1[pos1++])
pos2++;
while (pos1 < len1&&vis[pos1])
pos1++;
}
if (pos2 == len2)
return true;
return false;
}
int main(){
scanf("%s%s", s1, s2);
len1 = strlen(s1);
len2 = strlen(s2);
for (int i = 0; i < len1; i++){
scanf("%d", &a[i]);
}
int l = 0, r = len1;
int ans;
while (l <= r){
int mid = l + r >> 1;
if (check(mid)){
l = mid + 1;
ans = mid;
}
else
r = mid - 1;
}
printf("%d\n", ans);
}