Advertisement
ivnikkk

Untitled

Nov 15th, 2022
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "bits/stdc++.h"
  3. using namespace std;
  4. #define all(a) a.begin(), a.end()
  5. using namespace std;
  6. typedef long double ld;
  7. signed main() {
  8. #ifdef _DEBUG
  9.     freopen("input.txt", "r", stdin);
  10.     freopen("output.txt", "w", stdout);
  11. #endif
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(nullptr);
  14.     string s; cin >> s;
  15.     vector<vector<int>> res;
  16.     deque<int> null;
  17.     set<int> close, open;
  18.     for (int i = 0; i < (int)s.size(); i++) {
  19.         if (s[i] == '1') {
  20.             if (!close.empty()) {
  21.                 res[*close.begin()].push_back(i);
  22.                 open.insert(*close.begin());
  23.                 close.erase(*close.begin());
  24.             }
  25.             else {
  26.                 res.push_back({});
  27.                 if (null.empty()) {
  28.                     cout << -1;
  29.                     return 0;
  30.                 }
  31.                 res.back().push_back(null.front());
  32.                 res.back().push_back(i);
  33.                 open.insert((int)res.size() - 1);
  34.                 null.pop_front();
  35.             }
  36.         }
  37.         if (s[i] == '0') {
  38.             if(open.empty()) {
  39.                 null.push_back(i);
  40.             }
  41.             else {
  42.                 res[*open.begin()].push_back(i);
  43.                 close.insert(*open.begin());
  44.                 open.erase(*open.begin());
  45.             }
  46.         }
  47.     }
  48.     if (!open.empty()) {
  49.         cout << -1 << '\n';
  50.     }
  51.     else {
  52.         cout << (int)res.size() + (int)null.size();
  53.         cout << '\n';
  54.         for (vector<int>& it : res) {
  55.             cout << (int)it.size() <<  ' ';
  56.             for (int i = 0; i < (int)it.size(); i++) {
  57.                 cout << it[i] + 1 << ' ';
  58.             }
  59.             cout << '\n';
  60.         }
  61.         for (int i = 0; i < (int)null.size(); i++) {
  62.             cout << "1 " << null[i] + 1 << '\n';
  63.         }
  64.     }
  65.    
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement