1 solutions
-
0
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int cnt=0; stack<pair<int,int>> stk; for(int i=1;i<=n;i++) { int x; cin>>x; if(stk.size()==0||stk.top().first!=x) //新开一个 { stk.push({x,1}); cnt++;//多了一个 } else { auto t=stk.top(); stk.pop(); t.second++;//多了一个 cnt++; if(t.second==t.first) //可以删除 { cnt-=t.second; } else { stk.push(t); //不能删除(放回去) } } cout<<cnt<<endl; } return 0; }
- 1
Information
- ID
- 2750
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 12
- Accepted
- 5
- Uploaded By