Sanath12345

Untitled

May 31st, 2021
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. //Problem link :
  2. //done by sanath kumar
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long int
  6. #define ld long double
  7. #define mod 1000000007
  8. #define inf 1e9
  9. #define endl "\n"
  10. #define pb push_back
  11. #define vi vector<ll>
  12. #define vs vector<string>
  13. #define pii pair<ll,ll>
  14. #define ump unordered_map
  15. #define mp make_pair
  16. #define pq_max priority_queue<ll>
  17. #define pq_min priority_queue<ll,vector<ll>,greater<ll>>
  18. #define all(v) v.begin(),v.end()
  19. #define ff first
  20. #define ss second
  21. #define mid(l,r) (l+(r-l))/2
  22. #define bitc(x) __builtin_popcount(x)
  23. #define loop(i,a,b) for(int i=(a);i<=(b);i++)
  24. #define looprev(i,a,b) for(int i=(a);i>=(b);i--)
  25. #define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
  26. #define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
  27. #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
  28. template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
  29. template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
  30.  
  31. void err(istream_iterator<string> it){}
  32. template<typename T,typename... Args>
  33. void err(istream_iterator<string> it,T a,Args... args){
  34. cout<<*it<<" = "<<a<<endl;
  35. err(++it,args...);
  36. }
  37. void file_i_o(){
  38. ios_base::sync_with_stdio(false);
  39. cin.tie(0);
  40. cout.tie(0);
  41. #ifndef ONLINE_JUDGE
  42. freopen("input.txt","r",stdin);
  43. freopen("output.txt","w",stdout);
  44. #endif
  45. }
  46. ll *getfactorial(){
  47. int m=1e6;
  48. ll *fact=new ll[m+1];
  49. fact[0]=1;
  50. loop(i,1,m){
  51. fact[i]=(fact[i-1]*i)%mod;
  52. }
  53. // time complexity O(n)
  54. return fact;
  55. }
  56. vi *getfactors(){
  57. int n=2e5;
  58. vi *factors=new vi[n+5];
  59. loop(i,1,n){
  60. for(int j=i;j<=n;j+=i){
  61. factors[j].pb(i);
  62. }
  63. }
  64. // time complexity O(nlogn)
  65. return factors;
  66. }
  67. ll power(ll a,ll b,ll m=mod){
  68. if(b==0) return 1;
  69. ll smallans=power(a,b/2,m);
  70. ll ans=(smallans*smallans)%m;
  71. if(b%2==1){
  72. ans=(ans*a)%m;
  73. }
  74. return ans;
  75. // time complexity O(logb)
  76. }
  77. bool *isprime(){
  78. int m=1e6;
  79. bool *p=new bool[m];
  80. loop(i,0,m) p[i]=true;
  81. p[0]=false;
  82. p[1]=false;
  83. loop(i,2,sqrt(m)){
  84. for(int j=2*i;j<=m;j+=i){
  85. p[j]=false;
  86. }
  87. }
  88. // time complexity O(nloglogn)
  89. return p;
  90. }
  91. ll nCr(ll n,ll r,int m=mod){
  92. if(n<r) return 0;
  93. ll dp[2][r+5];
  94. memset(dp,0,sizeof(dp));
  95. int i=1;
  96. loop(k,0,n) dp[k][0]=1;
  97. loop(k,1,n){
  98. loop(j,1,r){
  99. dp[i][j]=dp[i^1][j]+dp[i^1][j-1];
  100. }
  101. i=i^1;
  102. }
  103. // time complexity O(n*r) ,in worst case O(n^2)
  104. return dp[i^1][r];
  105. }
  106.  
  107. //==================START==================
  108.  
  109. int main(){
  110. file_i_o();
  111. clock_t begin=clock();
  112. int t;
  113. cin>>t;
  114. while(t--){
  115. int n,m;
  116. cin>>n>>m;
  117. string S;
  118. cin>>S;
  119. int arr[n];
  120. int k=0;
  121. loop(i,0,n-1){
  122. if(S[i]=='1'){
  123. arr[k]=i;
  124. k++;
  125. }
  126. }
  127. if(k==0){
  128. cout<<S<<endl;
  129. continue;
  130. }
  131. int p=0;
  132. loop(i,0,n-1){
  133. if(S[i]=='0'){
  134. auto idx=lower_bound(arr,arr+k,i)-arr;
  135. int x=abs(i-arr[idx]);
  136. int y=INT_MAX;
  137. if(idx!=0){
  138. y=abs(i-arr[idx-1]);
  139. }
  140. if(min(x,y)<=m and x!=y){
  141. S[i]='1';
  142. }
  143. }
  144. }
  145. cout<<S<<endl;
  146. }
  147. #ifndef ONLINE_JUDGE
  148. clock_t end=clock();
  149. cout<<"\n\n\nExecuted in :"<<double(end-begin)/CLOCKS_PER_SEC*1000<<" ms"<<endl;
  150. #endif
  151. }
Advertisement
Add Comment
Please, Sign In to add comment