답안 #366350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366350 2021-02-14T04:03:32 Z CodePlatina Po (COCI21_po) C++14
70 / 70
12 ms 1152 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    int arr[n]; for(auto &i : arr) cin >> i;
    vector<int> Q{0};
    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        while(Q.size() && Q.back() > arr[i]) Q.pop_back(), ++ans;
        if(Q.empty() || Q.back() != arr[i]) Q.push_back(arr[i]);
    }
    cout << ans + (int)Q.size() - 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 6 ms 620 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 12 ms 748 KB Output is correct