Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n;
  5. string s;
  6. vector<vector<int>> ans;
  7.  
  8. int main()
  9. {
  10. cin >> n >> s;
  11. for(int i = n; i >= 1; --i)
  12. {
  13. int switches = 0;
  14. vector<bool> switched(n, false);
  15. vector<int> h;
  16. for(int j = 0; j < n && switches < i; ++j)
  17. if (s[j] == '1')
  18. {
  19. switched[j] = true;
  20. switches++;
  21. h.push_back(j);
  22. }
  23.  
  24. if (switches < i)
  25. {
  26. for (int j = 0; j < n && switches < i; ++j)
  27. if (switched[j] == false)
  28. {
  29. switches++;
  30. h.push_back(j);
  31. }
  32. }
  33.  
  34. assert(switches == i);
  35. sort(h.begin(), h.end());
  36. ans.push_back(h);
  37. for(auto j: h)
  38. s[j] ^= 1;
  39. }
  40.  
  41. bool ok = 1;
  42. for(auto i: s) ok &= i == '0';
  43. if (!ok)
  44. {
  45. cout << "No" << endl;
  46. return 0;
  47. }
  48.  
  49. cout << "Yes" << endl;
  50. reverse(ans.begin(), ans.end());
  51. for(auto i: ans)
  52. {
  53. for(auto j: i) cout << j + 1 << ' ';
  54. cout << endl;
  55. }
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement