Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<bits/stdc++.h>
- using namespace std;
- #define pi acos(-1.0)
- #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define ll long long
- #define pb push_back
- #define fi first
- #define se second
- #define in insert
- #define mp make_pair
- #define GCD(a,b) __gcd(a,b);
- #define endl "\n"
- #define FRU freopen("out.txt","w",stdout)
- #define FRO freopen("in.txt","r",stdin)
- #define INFLL 9223372036854775807
- #define debug 0
- #define MAXN 100001
- //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
- int main()
- {
- fastio;
- ll t;
- cin>>t;
- while(t--)
- {
- ll n,k;
- cin>>n>>k;
- string s;
- cin>>s;
- ll i,j,c=0,f,m,ff;
- for(i=0;i<n;i++)
- {
- if(s[i]=='0')
- {
- f=1,m=1;
- for(j=i;j>=(i-k);j--)
- {
- if(s[j]=='1')
- {
- f=0;
- break;
- }
- }
- if(f)
- {
- for(ff=i;ff<=(i+k);ff++)
- {
- if(s[ff]=='1')
- {
- m=0;
- break;
- }
- }
- if(m)
- {
- s[i]='1';
- c++;
- i+=k-1;
- }
- }
- }
- }
- cout<<c<<endl;
- }
- }
Add Comment
Please, Sign In to add comment