lina_os

Untitled

Apr 29th, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define ld long double
  5.  
  6. using namespace std;
  7.  
  8. string s;
  9. string t;
  10.  
  11. bool can(vector<ll>v, ll m) {
  12. set<ll>ss(v.begin()+m+1, v.end());
  13. string n;
  14. for (auto i:ss) {
  15. n.push_back(s[i-1]);
  16. }
  17. ll j=0;
  18. for (auto i:n) {
  19. if (i==t[j]) j++;
  20. if (j==t.size()) return true;
  21. }
  22. return false;
  23. }
  24.  
  25. int main() {
  26. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  27. cin >> s >> t;
  28. ll n=s.size();
  29. vector<ll>v(n);
  30. for (auto &i:v) cin >> i;
  31. ll l=0, r=n-1, m;
  32. while (l<=r) {
  33. m = (l + r) / 2;
  34. if (can(v, m)) {
  35. if (m==n-1 || !can(v,m+1)) {
  36. cout << m+1 << endl;
  37. return 0;
  38. }
  39. else l=m+1;
  40. }
  41. else r=m-1;
  42. }
  43. cout << 0 << endl;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment