#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;cin>>n;
vector<ll>arr(n);
for(auto &i:arr)cin>>i;
vector<ll>v;
ll ans=0;
for(ll i=0;i<n;i++){
if(arr[i]==0){
v.push_back(0);
continue;
}
while(v.size() && v[v.size()-1]>arr[i]){
v.pop_back();
}
if(!v.size())ans++;
else if(v[v.size()-1]<arr[i])ans++;
v.push_back(arr[i]);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
11 ms |
820 KB |
Output is correct |
5 |
Correct |
16 ms |
1020 KB |
Output is correct |
6 |
Correct |
47 ms |
1712 KB |
Output is correct |
7 |
Correct |
46 ms |
1080 KB |
Output is correct |