fork download
  1. #include<bits/stdc++.h>
  2. #define ld long double
  3. #define int long long
  4. #define all(v) v.begin(),v.end()
  5. #define allr(v) v.rbegin(),v.rend()
  6. using namespace std;
  7. void solve(){
  8. string s,t;
  9. cin>>s>>t;
  10. map<char,vector<int>>mp;
  11. int n=s.length(),m=t.length();
  12. for (int i=0;i<m;i++) {
  13. mp[t[i]].push_back(i);
  14. }
  15. int x=0,inds=-1,indt=-1;
  16. for (int i=0;i<n;i++) {
  17. if (!mp[s[i]].empty()) {
  18. int l=0,r=mp[s[i]].size()-1;
  19. vector<int>v=mp[s[i]];
  20.  
  21. while (l<=r) {
  22. int mid=(l+r)/2;
  23. int sz=m-v[mid];
  24. if (sz+i>=3&&(i!=0&&sz!=2)) {
  25. indt=v[mid];
  26. l=mid+1;
  27. }else r=mid-1;
  28. }
  29. if (indt!=-1) {
  30. inds=i;
  31. break;
  32. }
  33. }
  34. }
  35. if (inds==-1||indt==-1) {
  36. cout<<"-1\n";
  37. return;
  38. }
  39. string ans=s.substr(0, inds);
  40. ans+=t.substr(indt, m);
  41. cout<<ans<<"\n";
  42. }
  43. int32_t main() {
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(nullptr);
  46. cout.tie(nullptr);
  47. int t=1;
  48. //cin>>t;
  49. while(t--){
  50. solve();
  51. }
  52. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
-1