Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- #define pb push_back
- #define all(x) (x).begin(),(x).end()
- #define ll long long
- #define ld long double
- #define eps 1e-9
- #define sz(a) (ll)(a).size()
- #define ppc __builtin_popcount
- #define ppcll __builtin_popcountll
- #define endl "\n"
- #define lb lower_bound
- #define ub upper_bound
- const ld PI = acos(-1.0);
- const int MOD = 1e9 +7;
- const ll INF = 1e18;
- // if(abs(a-b)<eps) --> if(a==b)
- // fixed << setprecision(n) -->printing decimal till n
- // hypot(a ,b) --> sqrt(a^2 + b^2)
- using namespace std;
- void solve(){
- string s,t1;
- cin>>s>>t1;
- vector<vector<ll>>dp(26);
- for(int i=0;i<sz(s);i++){
- dp[s[i]-'a'].pb(i);
- }
- ll ind =0;
- ll copies =1;
- for(int i=0;i<sz(t1);i++){
- if(dp[t1[i]-'a'].size()==0){
- cout<<-1<<endl;
- return;
- }
- auto it = lb(all(dp[t1[i]-'a']) , ind);
- if(it==dp[t1[i]-'a'].end()){
- //again chekcing
- ind =0;
- copies++;
- auto it1 = lb(all(dp[t1[i]-'a']) , ind);
- ind = *it1;
- }
- else{
- ind = *it;
- }
- }
- cout<<copies*sz(s) - sz(s) + ind+1 <<endl;
- }
- int main(){
- IO;
- ll t =1;
- // cin>>t;
- for(int i=1;i<=t;i++){
- // cout<<"Case #"<<i<<": ";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment