#include <iostream>
#include <stack>
#define ll long long
using namespace std;
ll a[100001], n, ans = 0;
stack<int> s;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
while (!s.empty() && s.top() > a[i]) s.pop();
if (!s.empty() && s.top() == a[i]) continue;
if (a[i]) s.push(a[i]), ans++;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
14 ms |
716 KB |
Output is correct |
5 |
Correct |
15 ms |
980 KB |
Output is correct |
6 |
Correct |
66 ms |
2192 KB |
Output is correct |
7 |
Correct |
38 ms |
2016 KB |
Output is correct |