답안 #782752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782752 2023-07-14T08:57:52 Z 1075508020060209tc Po (COCI21_po) C++14
70 / 70
29 ms 2464 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int n;
int ar[500005];

signed main(){
int ans=0;
cin>>n;
for(int i=1;i<=n;i++){
    cin>>ar[i];
}
stack<int>stk;
for(int i=1;i<=n;i++){
    while(stk.size()&&stk.top()>ar[i]){stk.pop();}
    if(stk.size()&&stk.top()==ar[i]){continue;}
    if(ar[i]==0){continue;}
    stk.push(ar[i]);
    ans++;
}
cout<<ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 7 ms 712 KB Output is correct
5 Correct 10 ms 1088 KB Output is correct
6 Correct 29 ms 2464 KB Output is correct
7 Correct 29 ms 1992 KB Output is correct