D. String Game
链接:
http://codeforces.com/contest/779/problem/D
代码 :
1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6 #include <cstdio> 7 #include <string> 8 #include <vector> 9 #include <cstring> 10 #include <iostream> 11 #include <algorithm> 12 #include <functional> 13 using namespace std; 14 #define rep(i,a,n) for (int i=a;i<=n;i++) 15 #define per(i,a,n) for (int i=n;i>=a;i--) 16 #define pb push_back 17 #define mp make_pair 18 #define all(x) (x).begin(),(x).end() 19 #define fi first 20 #define se second 21 #define SZ(x) ((int)(x).size()) 22 typedef vector<int> VI; 23 typedef long long ll; 24 typedef pair<int, int> PII; 25 const ll mod = 1e9 + 7; 26 const int inf = 0x3f3f3f3f; 27 const double eps = 1e-7; 28 // head 29 30 const int maxn = 2e5 + 7; 31 int a[maxn]; 32 char p[maxn], t[maxn], s[maxn]; 33 int len; 34 35 bool check(int k) { 36 rep(i, 1, len) s[i] = t[i]; 37 rep(i, 1, k) s[a[i]] = ' '; 38 int j = 1; 39 rep(i, 1, len) { 40 if (s[i] == p[j]) j++; 41 if (j > strlen(p + 1)) return true; 42 } 43 return false; 44 } 45 46 int main() { 47 scanf("%s%s", t + 1, p + 1); 48 len = strlen(t + 1); 49 rep(i, 1, len) scanf("%d", a + i); 50 int l = 0, r = len, ans = 0; 51 while (l <= r) { 52 int mid = (l + r) / 2; 53 if (check(mid)) l = mid + 1, ans = mid; 54 else r = mid - 1; 55 } 56 cout << ans << endl; 57 return 0; 58 }