Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define dim 1000009
- using namespace std;
- typedef long long ll;
- ll n,m,a,b;
- string s;
- ll p[dim];
- ll C[dim][3];
- ll func(ll x, ll c)
- {
- if (x > n) return 0;
- if (C[x][c] != 0) return C[x][c];
- if (c == 0)
- {
- if (x+a-1 > n) return 0;
- return C[x][c] = a + func(x+a,1);
- }
- else
- {
- if (x+b-1 > n) return 0;
- if (p[x+b-1] - p[x-1] < b) return 0;
- return C[x][c] = b + func(x+b,0);
- }
- return C[x][c];
- }
- int main()
- {
- cin>>n;
- cin>>s;
- s = " " + s;
- cin>>m>>b>>a;
- ll res = 0;
- for (int i = 1; i <= n; i++)
- {
- p[i] = p[i-1];
- if (s[i] == '1') p[i]++;
- }
- ll nd = m*(a+b);
- for (int i = 1; i <= n-nd+1; i++)
- {
- res += (func(i,1) >= nd ? 1 :0);
- }
- cout<<res<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement