제출 #1153894

#제출 시각아이디문제언어결과실행 시간메모리
1153894jmuzhenPo (COCI21_po)C++20
20 / 70
22 ms580 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()) {
      st.push(x);
      ans++;
      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
      st.pop();
    }

    // if equal, then don't need to increment this one
    if (!st.empty() && st.top() == x) {
      continue;
    }

    st.push(x); // create a new layer for us
    ans++;
  }

  // // the left-over ones also need to be popped
  // while (!st.empty()) {
  //   st.pop();
  //   ans++;
  // }

  cout << ans << endl;

}
#Verdict Execution timeMemoryGrader output
Fetching results...