Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. vector<int> ans;
  2.  
  3. int main() {
  4.     int n;
  5.     cin >> n;
  6.     vector<int> a(n);
  7.     for (auto &i:a)
  8.         cin>>i;
  9.     memset(in, 0, sizeof in);
  10.     int day = 1;
  11.     for (int i= 0; i< a.size(); ++i) {
  12.         update (abs(a[i]), sign(a[i]));
  13.         // employee already entered that day and is entering
  14.         if (in[abs(a[i])] == day && a[i] > 0) {
  15.             cout << -1 << endl;
  16.             return 0;
  17.         }
  18.         // employee didnt entered that day and is leaving
  19.         if (in[abs(a[i])] < day && a[i] < 0) {
  20.             cout << -1 << endl;
  21.             return 0;
  22.         }
  23.         // employee entered that day
  24.         if (a[i] > 0)
  25.             in[a[i]] = day;
  26.         int q = query();
  27.         // office is empty new day starts
  28.         if (q == 0) {
  29.             ans.pb(i+1);
  30.             day++;
  31.         }
  32.     }
  33.     // office is not empty
  34.     int q = query();
  35.     if (q != 0)
  36.         cout << -1 << endl;
  37.     else {
  38.         cout << ans.size() << endl;
  39.         for (int i= 0; i< ans.size(); ++i) {
  40.             if (i) {
  41.                 cout << " " << ans[i]-ans[i-1];
  42.             } else
  43.                 cout << ans[i];
  44.         }
  45.         cout << '\n';
  46.     }
  47.    
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement