Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- using namespace std;
- string s;
- string t;
- bool can(vector<ll>v, ll m) {
- set<ll>ss(v.begin()+m+1, v.end());
- string n;
- for (auto i:ss) {
- n.push_back(s[i-1]);
- }
- ll j=0;
- for (auto i:n) {
- if (i==t[j]) j++;
- if (j==t.size()) return true;
- }
- return false;
- }
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- cin >> s >> t;
- ll n=s.size();
- vector<ll>v(n);
- for (auto &i:v) cin >> i;
- ll l=0, r=n-1, m;
- while (l<=r) {
- m = (l + r) / 2;
- if (can(v, m)) {
- if (m==n-1 || !can(v,m+1)) {
- cout << m+1 << endl;
- return 0;
- }
- else l=m+1;
- }
- else r=m-1;
- }
- cout << 0 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment