Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- inline int getID(char c) {
- return ('a' <= c && c <= 'z') ? c-'a' : c-'A'+26;
- }
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- int m, n; cin >> m >> n;
- string t, s; cin >> t >> s;
- int targetF[52]{}, f[52]{};
- for (char c : t) ++targetF[getID(c)];
- for (int i = 0; i < m-1; ++i) ++f[getID(s[i])];
- int differences = 0;
- for (int i = 0; i < 52; ++i) differences += targetF[i] != f[i];
- int total = 0;
- for (int i = m-1; i < n; ++i) {
- // add
- int c = getID(s[i]);
- ++f[c];
- if (f[c] == targetF[c]) --differences;
- else if (f[c] == targetF[c]+1) ++differences;
- // check
- if (!differences) ++total;
- // remove
- c = getID(s[i-m+1]);
- --f[c];
- if (f[c] == targetF[c]) --differences;
- else if (f[c] == targetF[c]-1) ++differences;
- }
- cout << total << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement