#include<bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
stack<int> s;
for(int i = 0; i < n; i++) {
int x;
cin >> x;
while(s.size()&&s.top()>x)
s.pop();
if(s.size()&&s.top()==x)
continue;
if(x)
ans++,s.push(x);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
428 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
7 ms |
604 KB |
Output is correct |
5 |
Correct |
10 ms |
600 KB |
Output is correct |
6 |
Correct |
30 ms |
1572 KB |
Output is correct |
7 |
Correct |
36 ms |
1300 KB |
Output is correct |