achulkov2

Untitled

Mar 22nd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. ios::sync_with_stdio(false);
  6. int n, m;
  7. cin >> n >> m;
  8. string g, s;
  9. cin >> g >> s;
  10. map<char, int> a;
  11. for(int i = 0; i < n; i++)
  12. a[g[i]]++;
  13.  
  14. int ans = 0;
  15. for(int i = 0; i < m; i++){
  16. //cerr << i << " " << a.size() << endl;
  17. a[s[i]]--;
  18. //cerr << "- " << s[i] << " " << a[s[i]] << endl;
  19. if(i >= n){
  20. a[s[i-n]]++;
  21. //cerr << "+ " << s[i-n] << " " << a[s[i-n]] << endl;
  22. if(a[s[i-n]] == 0)
  23. a.erase(a.find(s[i-n]));
  24. }
  25. if(a[s[i]] == 0)
  26. a.erase(a.find(s[i]));
  27. if(a.size() == 0)
  28. ans++;
  29. }
  30.  
  31. cout << ans;
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment