Created
April 22, 2020 20:02
-
-
Save fardinabir/34f681eaab31f5f60676e383f4451d5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define mx 1000005 | |
#define ll long long int | |
#define test_case printf("Case %d:\n",id++); | |
using namespace std; | |
ll cnt_zero[mx],n; | |
string arr; | |
int main() | |
{ | |
ll t,i,j,k,l,a,b,c=0,p,one=0,e,u,v,q,sum,id=1,x,y; | |
cin>>t; | |
while(t--) | |
{ | |
scanf("%lld %lld",&n,&k); | |
cin>>arr; | |
one=sum=0; //fardinabirs.wordpress.com | |
for(i=0;i<n;i++) | |
{ | |
if(arr[i]=='1') | |
one++; | |
if(arr[i]=='0') | |
cnt_zero[one]++; // counting zero after the one'th occurrence of 1 | |
if(one>=k) | |
sum+=cnt_zero[one-k]+(k!=0); //the number of zero between the before the starting point | |
} | |
cout<<sum<<endl; | |
memset(cnt_zero,0,sizeof cnt_zero); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment