-
Notifications
You must be signed in to change notification settings - Fork 0
/
B. Silly Mistake.cpp
50 lines (50 loc) · 1019 Bytes
/
B. Silly Mistake.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,a,i,cn=0,flag=0,prev=0;
cin>>n;
map<ll,bool>mp,vis;
vector<ll>arr;
for(i=0;i<n;i++)
{
cin>>a;
if(a>0)
{
cn++;
if(mp.count(a)==true)
{
flag=1;
continue;
}
mp[a]=true;
}
else
{
if(mp.count(-a)==false || vis[-a]==true)
{
flag=1;
continue;
}
cn--;
vis[-a]=true;
if(cn==0)
{
arr.push_back(i-prev+1);
prev=i+1;
mp.clear();
vis.clear();
}
}
}
if(flag || cn>0)
cout<<"-1"<<endl;
else
{
cout<<arr.size()<<endl;
for(i=0;i<arr.size();i++)
cout<<arr[i]<<" ";
}
return 0;
}