Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- using namespace std;
- typedef long double ld;
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- string s; cin >> s;
- vector<vector<int>> res;
- deque<int> null;
- set<int> close, open;
- for (int i = 0; i < (int)s.size(); i++) {
- if (s[i] == '1') {
- if (!close.empty()) {
- res[*close.begin()].push_back(i);
- open.insert(*close.begin());
- close.erase(*close.begin());
- }
- else {
- res.push_back({});
- if (null.empty()) {
- cout << -1;
- return 0;
- }
- res.back().push_back(null.front());
- res.back().push_back(i);
- open.insert((int)res.size() - 1);
- null.pop_front();
- }
- }
- if (s[i] == '0') {
- if(open.empty()) {
- null.push_back(i);
- }
- else {
- res[*open.begin()].push_back(i);
- close.insert(*open.begin());
- open.erase(*open.begin());
- }
- }
- }
- if (!open.empty()) {
- cout << -1 << '\n';
- }
- else {
- cout << (int)res.size() + (int)null.size();
- cout << '\n';
- for (vector<int>& it : res) {
- cout << (int)it.size() << ' ';
- for (int i = 0; i < (int)it.size(); i++) {
- cout << it[i] + 1 << ' ';
- }
- cout << '\n';
- }
- for (int i = 0; i < (int)null.size(); i++) {
- cout << "1 " << null[i] + 1 << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement