Facebook
From Toxic Parrot, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 151
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define sz(s) int((s).size())
  4. const int AL = 26;
  5. const int N = 2e5 + 10;
  6.  
  7. string s, t;
  8. int pre[N], suff[N], pos[AL], ind;
  9.  
  10. int main(){
  11.         ios::sync_with_stdio(0);
  12.         cin.tie(0);
  13.  
  14.         cin >> s >> t;
  15.         for(int i = 0; i < sz(s); ++ i){
  16.                 if(ind < sz(t) && s[i] == t[ind])
  17.                         pos[s[i] - 'a'] = ind ++;
  18.                 pre[i] = pos[s[i] - 'a'];
  19.         }
  20.         ind = sz(t) - 1; memset(pos, 0, sizeof(pos));
  21.         for(int i = sz(s) - 1; i >= 0; -- i){
  22.                 if(ind >= 0 && s[i] == t[ind])
  23.                         pos[s[i] - 'a'] = sz(t) - (ind --);
  24.                 suff[i] = pos[s[i] - 'a'];
  25.         }      
  26.        
  27.         for(int i = 0; i < sz(s); ++ i)
  28.                 if(pre[i] + suff[i] < sz(t)) return cout << "No\n", 0;
  29.         cout << "Yes\n";
  30.        
  31.         return 0;
  32. }