-
Notifications
You must be signed in to change notification settings - Fork 4
/
String Game.cpp
56 lines (54 loc) · 1.23 KB
/
String Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
string t, p;
vector<long long int> a;
bool check(long long int x) {
long long int i = 0, j = 0;
string temp = "";
unordered_set<long long int> set;
for(long long int k=1; k<=x; k++) {
set.insert(a[k]-1);
}
long long int lt = t.length();
for(long long int i=0; i<lt; i++) {
if(set.find(i) == set.end()) {
temp += t[i];
}
}
// cout << "temp is: " << temp << endl;
long long int ltemp = temp.length(), lp = p.length();
while( i < ltemp && j < lp ) {
while(i < ltemp && temp[i] != p[j]) i++;
if(temp[i] == p[j]) {
i++; j++;
}
}
return j == lp;
}
int main() {
cin >> t;
cin >> p;
long long lt = t.length(), lp = p.length();
a.resize(lt+1);
for(long long int i=1; i<=lt; i++) {
cin >> a[i];
}
//Corner cases
if(lp == 0) {
cout << lt << endl;
return 0;
}
long long int l = 0, r = lt-lp + 1;
while(l+1 < r) {
long long int mid = (l+r)/2;
if(check(mid) == true) {
l = mid;
}
else {
r = mid;
}
}
cout << l << "\n";
}