Advertisement
newb_ie

Untitled

Sep 15th, 2021
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. const int maxN = 2e5 + 10;
  5. int pos[maxN];
  6. bool bad[maxN];
  7.  
  8. bool find_subsequence (string &s,string &t) {
  9. int j = 0;
  10. for (int i = 0; i < (int) s.size(); ++i) {
  11. if (s[i] == t[j]) ++j;
  12. if (j == (int) t.size()) return true;
  13. }
  14. return false;
  15. }
  16.  
  17. bool yes (string & s,string & t,int x) {
  18. for (int i = 1; i < maxN; ++i) bad[i] = false;
  19. for (int i = 1; i <= x; ++i) bad[pos[i]] = true;
  20. string s2 = "";
  21. for (int i = 0; i < (int) s.size(); ++i) {
  22. if (bad[i + 1] == true) continue;
  23. s2.push_back(s[i]);
  24. }
  25. if (find_subsequence(s2,t)) return true;
  26. else return false;
  27. }
  28.  
  29. int main () {
  30. ios::sync_with_stdio(false);
  31. cin.tie(nullptr);
  32. cout.tie(nullptr);
  33. int T = 1;
  34. //~ cin >> T;
  35. for (int test_case = 1; test_case <= T; ++test_case) {
  36. string s,t;
  37. cin >> s >> t;
  38. int n = (int) s.size();
  39. for (int i = 1; i <= n; ++i) cin >> pos[i];
  40. int res = 0;
  41. int l = 1,r = n;
  42. while (l <= r) {
  43. long long mid = l + (r - l) / 2;
  44. if (yes(s,t,mid)) {
  45. l = mid + 1;
  46. res = mid;
  47. } else {
  48. r = mid - 1;
  49. }
  50. }
  51. cout << res << '\n';
  52. }
  53. //~ cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
  54. }
  55.  
  56.  
  57. Problem Link : https://codeforces.com/problemset/problem/778/A
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement