fork(2) download
#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

int main()

{

long int m,n,k,count,i,j,sum;

char str[1000001];

scanf("%ld",&m);

while(m--)

{

scanf("%ld %ld",&n,&k);

scanf("%s",str);count=0;

i=0;

while(i<n-k)

{sum=0;

if(str[i]=='1'){

for(j=i+1;j<=i+k;j++)

{if(str[j]=='1')

sum++;

}

if(sum==k){

str[j-1]='0';count++;i=j-1;}

else

    i++;

}

else if(str[i]=='0')

{

for(j=i+1;j<=i+k;j++)

{if(str[j]=='0')

sum++;

}

if(sum==k){

str[j-1]='1';count++;i=j-1;}

else

    i++;

}

}

printf("%ld\n",count);

for(i=0;i<n;i++)

printf("%c",str[i]);

printf("\n");

}

return 0;

}





Success #stdin #stdout 0s 3996KB
stdin
2
2 2
11
2 1
11
stdout
0
11
1
10