Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #define MAX 200005
- #include <cstring>
- using namespace std;
- char s[MAX];
- int pred[MAX], cz[MAX], cu[MAX], vz, vu, sol;
- void afisare(int n, int nr);
- int main()
- {
- cin >> (s + 1);
- int n = strlen(s + 1);
- for(int i = 1; i <= n; i++)
- {
- if(s[i] == '0')
- {
- if(vu)
- {
- cz[++vz] = i;
- pred[i] = cu[vu--];
- }
- else
- cz[++vz] = i, sol++;
- }
- else
- {
- if(vz)
- {
- cu[++vu] = i;
- pred[i] = cz[vz--];
- }
- else
- {
- cout << -1;
- return 0;
- }
- }
- }
- if(vu)
- {
- cout << -1;
- return 0;
- }
- cout << sol << '\n';
- for(int i = 1; i <= vz; i++)
- {
- afisare(cz[i], 0);
- cout << '\n';
- }
- return 0;
- }
- void afisare(int n, int nr)
- {
- if(n == 0)
- cout << nr << " ";
- else
- {
- afisare(pred[n], nr + 1);
- cout << n << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement