Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #pragma GCC target ("sse4")
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<string,int> psi;
- typedef map<int,int> mii;
- typedef map<long long,long long> mll;
- typedef map<string,int> msi;
- typedef map<char,int> mci;
- typedef set<int> si;
- typedef set<long long> sll;
- typedef set<string> ss;
- typedef set<char> sc;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef vector<char> vc;
- typedef vector<ll> vll;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<string>> vvs;
- typedef vector<vector<ll>> vvll;
- #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
- #define FORd(i,b,a) for (int i =b; i >= a; i--)
- #define sz(x) (int)(x).size()
- #define mp make_pair
- #define pb push_back
- #define f first
- #define s second
- #define ins insert
- const int MOD = 1000000007;
- //type functions here
- bool check(mci m,mci b)
- {
- for(auto x:m)
- {
- // cout<<x.f<<b[x.f]<<endl;
- if(b[x.f]<x.s) return false;
- }
- return true;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int tc=1;
- cin>>tc;
- FOR(w,1,tc)
- {
- string big="tt0ss00t",small="st";
- cin>>small>>big;
- mci m,b;
- for(auto x:small) m[x]++;
- int i=0,j=0,sze=sz(big),count=INT_MAX;
- while(i<sze&&j<sze)
- {
- while(i<sze&&check(m,b)==false)
- {
- b[big[i]]++;
- i++;
- }
- while(j<sze&&check(m,b)==true)
- {
- int curr=(i-1)-j+1;
- if(b[big[j]]==1) b.erase(big[j]);
- else b[big[j]]--;
- // cout<<j;
- j++;
- count=min(count,curr);
- }
- }
- if(count==INT_MAX) cout<<"-1"<<endl;
- else cout<<count<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement