답안 #372798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372798 2021-03-01T17:52:21 Z Nimbostratus Po (COCI21_po) C++17
70 / 70
14 ms 2668 KB
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define ppb pop_back
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define cln(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int long long
using pii = pair<int,int>;
using ll = long long;
const int maxn = 2e5+5;
const int inf = 2e9;
const int mod = 1e9+7;

int n,a[maxn],ans;
stack<int> st;

int32_t main () {
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++) cin >> a[i];
	ans = !!a[1];
	st.push(a[1]);
	for(int i=2;i<=n;i++) {
		while(!st.empty() && st.top() > a[i]) st.pop();
		if(st.empty() || st.top() < a[i]) ans += !!a[i];
		st.push(a[i]);
	}
	cout << ans << endl;
}	
	



# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 5 ms 876 KB Output is correct
5 Correct 7 ms 1132 KB Output is correct
6 Correct 14 ms 2668 KB Output is correct
7 Correct 13 ms 2176 KB Output is correct