Advertisement
deushiro

check1

Nov 17th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. int main()
  8. {
  9.     ios_base::sync_with_stdio(false);
  10.     cin.tie(0);
  11.     cout.tie(0);
  12.     int n;
  13.     vector<int> a(n, 0);
  14.     set<int> s;
  15.     cin >> n;
  16.     for(int i = 0; i < n; ++i){
  17.         cin >> a[i];
  18.     }
  19.     vector<int> ans;
  20.     int c;
  21.  
  22.     for(int i = 0; i < n; ++i){
  23.         ++c;
  24.         if(a[i] < 0 && !s.count(a[i])){
  25.             cout << -1 << endl;
  26.             return 0;
  27.         }
  28.         else if(a[i] < 0 && s.count(-a[i])){
  29.             s.erase(-a[i]);
  30.         }
  31.         else if(a[i] > 0 && s.count(a[i])){
  32.             cout << -1 << endl;
  33.             return 0;
  34.         }
  35.         else if(a[i] > 0 && !s.count(a[i])){
  36.             s.insert(a[i]);
  37.         }
  38.         if(s.size() == 0){
  39.             ans.push_back(c);
  40.             c = 0;
  41.         }
  42.     }
  43.     if(s.size() > 0){
  44.         cout << -1 << endl;
  45.         return 0;
  46.     }
  47.     cout << ans.size();
  48.     for(int i = 0; i < n; ++i){
  49.         cout << ans[i] << " ";
  50.     }
  51.     cout << endl;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement