제출 #1153959

#제출 시각아이디문제언어결과실행 시간메모리
1153959jmuzhenPo (COCI21_po)C++20
70 / 70
23 ms664 KiB
#include<bits/stdc++.h> using namespace std; #define int long long using ll = long long; signed main() { int n; cin >> n; stack<int> st; int ans = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (st.empty() && x > 0) { st.push(x); ans++; // we increment answer when the segment starts continue; } while (!st.empty() && st.top() > x) { // decreasing; for example 3,2 -> need to end 3's layer because the 3 can't match another 3 to the right anymore // so we remove/end the segment of 3 st.pop(); } // if equal, then ignore this one since we're continuing the segment if (!st.empty() && st.top() == x) { continue; } if (x > 0) { st.push(x); // create a new segment for us ans++; // we increment answer when the segment starts } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...