Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- ios::sync_with_stdio(false);
- int n, m;
- cin >> n >> m;
- string g, s;
- cin >> g >> s;
- map<char, int> a;
- for(int i = 0; i < n; i++)
- a[g[i]]++;
- int ans = 0;
- for(int i = 0; i < m; i++){
- //cerr << i << " " << a.size() << endl;
- a[s[i]]--;
- //cerr << "- " << s[i] << " " << a[s[i]] << endl;
- if(i >= n){
- a[s[i-n]]++;
- //cerr << "+ " << s[i-n] << " " << a[s[i-n]] << endl;
- if(a[s[i-n]] == 0)
- a.erase(a.find(s[i-n]));
- }
- if(a[s[i]] == 0)
- a.erase(a.find(s[i]));
- if(a.size() == 0)
- ans++;
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment