Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const long long INF = 1e9 + 7;
- const int MAXN = 200 + 10;
- const int N = 1e5 + 10;
- int Sum(int a1, int n, int d) {
- return (2 * a1 + d * (n - 1)) * n / 2;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n, m;
- cin >> n >> m;
- string a, b;
- cin >> a >> b;
- map<int, int> cnt, kol;
- for (int i = 0; i < m; ++i) {
- ++cnt[b[i]];
- }
- int ans = 0, l = 0;
- for (int r = 0; r < n; ++r) {
- ++kol[a[r]];
- while (kol[a[r]] > cnt[a[r]] && l <= r) {
- --kol[a[l]];
- ++l;
- }
- ans += r - l + 1;
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment