Saleh127

CF 1367C

Jun 16th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. int main()
  7. {
  8. Faster
  9. test
  10. {
  11. string a;
  12. ll n,c,d,e=0,f=1,i,j,k,l;
  13. cin>>n>>k;
  14. cin>>a;
  15. for(i=0;i<n;i++)
  16. {
  17. if(a[i]=='1')
  18. {
  19. i+=k;
  20.  
  21. }
  22. else if(a[i]=='0')
  23. {
  24. f=1;
  25. c=i-k;
  26. d=i+k;
  27. if(c<0) c=0;
  28. if(d>n) d=n-1;
  29.  
  30. for(j=c; j<=d; j++)
  31. {
  32. if(a[j]=='1')
  33. {
  34. f=0;
  35. break;
  36. }
  37. }
  38. if(f)
  39. {
  40. a[i]='1';
  41. e++;
  42. i+=k;
  43. }
  44. }
  45. }
  46. cout<<e<<endl;
  47. }
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment