Submission #929163

# Submission time Handle Problem Language Result Execution time Memory
929163 2024-02-17T19:31:25 Z Karoot Baloni (COCI15_baloni) C++17
60 / 100
1759 ms 131072 KB
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>

#define all(x)  (x).begin(), (x).end()
#define rall(x)  (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;

ll linf = 1e15+1;

inline void scoobydoobydoo(){
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

set<int> bals[1000003];

int main(){
    scoobydoobydoo();
    int n; cin >> n;
    set<pair<int, int>> v;

    for (int i = 0; i < n; i++){
        int h; cin >> h;
        v.insert({i, h});
        bals[h].insert(i);
    }

    int sum = 0;

    while (!v.empty()){
        sum++;
        int h = (*v.begin()).second;
        int i = (*v.begin()).first;
        v.erase(v.begin());
        if (v.empty())break;
        if (bals[h-1].empty())break;
        auto it = bals[h-1].upper_bound(i);

        while (it != bals[h-1].end()){
            auto itr = v.find({*it, h-1});
            v.erase(itr);
            bals[h-1].erase(it);
            i = *it;
            h--;
            if (bals[h-1].empty())break;
            it = bals[h-1].upper_bound(i);
        }
    }

    cout << sum << endl;




    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 47452 KB Output isn't correct
2 Incorrect 11 ms 47452 KB Output isn't correct
3 Incorrect 11 ms 47684 KB Output isn't correct
4 Incorrect 12 ms 47708 KB Output isn't correct
5 Correct 1541 ms 125288 KB Output is correct
6 Correct 1759 ms 131072 KB Output is correct
7 Correct 1326 ms 119012 KB Output is correct
8 Correct 1315 ms 118036 KB Output is correct
9 Correct 1488 ms 122356 KB Output is correct
10 Correct 1545 ms 125264 KB Output is correct