Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #define MAX 200005
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. char s[MAX];
  9. int pred[MAX], cz[MAX], cu[MAX], vz, vu, sol;
  10.  
  11. void afisare(int n, int nr);
  12.  
  13. int main()
  14. {
  15. cin >> (s + 1);
  16.  
  17. int n = strlen(s + 1);
  18.  
  19. for(int i = 1; i <= n; i++)
  20. {
  21. if(s[i] == '0')
  22. {
  23. if(vu)
  24. {
  25. cz[++vz] = i;
  26. pred[i] = cu[vu--];
  27. }
  28. else
  29. cz[++vz] = i, sol++;
  30. }
  31. else
  32. {
  33. if(vz)
  34. {
  35. cu[++vu] = i;
  36. pred[i] = cz[vz--];
  37. }
  38. else
  39. {
  40. cout << -1;
  41. return 0;
  42. }
  43. }
  44. }
  45. if(vu)
  46. {
  47. cout << -1;
  48. return 0;
  49. }
  50. cout << sol << '\n';
  51.  
  52. for(int i = 1; i <= vz; i++)
  53. {
  54. afisare(cz[i], 0);
  55. cout << '\n';
  56. }
  57.  
  58. return 0;
  59. }
  60.  
  61. void afisare(int n, int nr)
  62. {
  63. if(n == 0)
  64. cout << nr << " ";
  65. else
  66. {
  67. afisare(pred[n], nr + 1);
  68. cout << n << " ";
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement