fork(2) download
  1. #include<iostream>
  2.  
  3. #include<cstdio>
  4.  
  5. #include<cstring>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10.  
  11. {
  12.  
  13. long int m,n,k,count,i,j,sum;
  14.  
  15. char str[1000001];
  16.  
  17. scanf("%ld",&m);
  18.  
  19. while(m--)
  20.  
  21. {
  22.  
  23. scanf("%ld %ld",&n,&k);
  24.  
  25. scanf("%s",str);count=0;
  26.  
  27. i=0;
  28.  
  29. while(i<n-k)
  30.  
  31. {sum=0;
  32.  
  33. if(str[i]=='1'){
  34.  
  35. for(j=i+1;j<=i+k;j++)
  36.  
  37. {if(str[j]=='1')
  38.  
  39. sum++;
  40.  
  41. }
  42.  
  43. if(sum==k){
  44.  
  45. str[j-1]='0';count++;i=j-1;}
  46.  
  47. else
  48.  
  49. i++;
  50.  
  51. }
  52.  
  53. else if(str[i]=='0')
  54.  
  55. {
  56.  
  57. for(j=i+1;j<=i+k;j++)
  58.  
  59. {if(str[j]=='0')
  60.  
  61. sum++;
  62.  
  63. }
  64.  
  65. if(sum==k){
  66.  
  67. str[j-1]='1';count++;i=j-1;}
  68.  
  69. else
  70.  
  71. i++;
  72.  
  73. }
  74.  
  75. }
  76.  
  77. printf("%ld\n",count);
  78.  
  79. for(i=0;i<n;i++)
  80.  
  81. printf("%c",str[i]);
  82.  
  83. printf("\n");
  84.  
  85. }
  86.  
  87. return 0;
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
Success #stdin #stdout 0s 3996KB
stdin
2
2 2
11
2 1
11
stdout
0
11
1
10