Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- const int maxN = 2e5 + 10;
- int pos[maxN];
- bool bad[maxN];
- bool find_subsequence (string &s,string &t) {
- int j = 0;
- for (int i = 0; i < (int) s.size(); ++i) {
- if (s[i] == t[j]) ++j;
- if (j == (int) t.size()) return true;
- }
- return false;
- }
- bool yes (string & s,string & t,int x) {
- for (int i = 1; i < maxN; ++i) bad[i] = false;
- for (int i = 1; i <= x; ++i) bad[pos[i]] = true;
- string s2 = "";
- for (int i = 0; i < (int) s.size(); ++i) {
- if (bad[i + 1] == true) continue;
- s2.push_back(s[i]);
- }
- if (find_subsequence(s2,t)) return true;
- else return false;
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- //~ cin >> T;
- for (int test_case = 1; test_case <= T; ++test_case) {
- string s,t;
- cin >> s >> t;
- int n = (int) s.size();
- for (int i = 1; i <= n; ++i) cin >> pos[i];
- int res = 0;
- int l = 1,r = n;
- while (l <= r) {
- long long mid = l + (r - l) / 2;
- if (yes(s,t,mid)) {
- l = mid + 1;
- res = mid;
- } else {
- r = mid - 1;
- }
- }
- cout << res << '\n';
- }
- //~ cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
- }
- Problem Link : https://codeforces.com/problemset/problem/778/A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement