Submission #780848

# Submission time Handle Problem Language Result Execution time Memory
780848 2023-07-12T13:56:21 Z borisAngelov Po (COCI21_po) C++17
70 / 70
9 ms 1888 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 100005;

int n;

int a[maxn];

stack<int> st;

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }

    int ans = 0;

    for (int i = 1; i <= n; ++i)
    {
        while (!st.empty() && st.top() > a[i])
        {
            st.pop();
        }

        if (!st.empty() && st.top() == a[i])
        {
            continue;
        }

        if (a[i] != 0)
        {
            ++ans;
            st.push(a[i]);
        }
    }

    cout << ans << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 8 ms 1888 KB Output is correct
7 Correct 9 ms 1572 KB Output is correct