Advertisement
Guest User

Untitled

a guest
Dec 28th, 2020
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1000043;
  6. int q;
  7. char buf[N];
  8. int n, k;
  9.  
  10. int ceilLog(int x)
  11. {
  12. int y = 0;
  13. while((1 << y) < x)
  14. y++;
  15. return y;
  16. }
  17.  
  18. int main()
  19. {
  20. scanf("%d", &q);
  21. for(int i = 0; i < q; i++)
  22. {
  23. scanf("%d %d", &n, &k);
  24. scanf("%s", buf);
  25. string s = buf;
  26. int m = min(k, ceilLog(n - k + 2));
  27. vector<int> used(1 << m, 0);
  28. vector<int> next0(n, int(1e9));
  29. if(s[n - 1] == '0')
  30. next0[n - 1] = n - 1;
  31. for(int j = n - 2; j >= 0; j--)
  32. if(s[j] == '0')
  33. next0[j] = j;
  34. else
  35. next0[j] = next0[j + 1];
  36. int d = k - m;
  37. for(int j = 0; j < n - k + 1; j++)
  38. {
  39. if(next0[j] - j < d)
  40. continue;
  41. int cur = 0;
  42. for(int x = j + d; x < j + k; x++)
  43. cur = cur * 2 + (s[x] - '0');
  44. used[((1 << m) - 1) ^ cur] = 1;
  45. }
  46. int ans = -1;
  47. for(int j = 0; j < (1 << m); j++)
  48. if(used[j] == 0)
  49. {
  50. ans = j;
  51. break;
  52. }
  53. if(ans == -1)
  54. puts("NO");
  55. else
  56. {
  57. puts("YES");
  58. string res(d, '0');
  59. string res2;
  60. for(int j = 0; j < m; j++)
  61. {
  62. res2.push_back('0' + (ans % 2));
  63. ans /= 2;
  64. }
  65. reverse(res2.begin(), res2.end());
  66. res += res2;
  67. puts(res.c_str());
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement