Submission #1339339

#TimeUsernameProblemLanguageResultExecution timeMemory
1339339Desh03Souvenirs (IOI25_souvenirs)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

void buy_souvenirs(int n, long long p0) {
    auto [x, y] = transaction(p0 - 1);
    vector<pair<long long, vector<int>>> q = {{p0 - 1 - y, x}};
    vector<long long> ans(n);
    vector<int> cnt(n);
    for (int t : x) {
        ++cnt[t];
    }
    ans[0] = p0;
    while (count(ans.begin(), ans.end(), 0)) {
        if (q.empty()) {
            for (int i = n - 2; i >= 0; i--) {
                if (ans[i] && !ans[i + 1]) {
                    auto [x, y] = transaction(ans[i] - 1);
                    for (int t : x) {
                        ++cnt[t];
                    }
                    vector<int> nv;
                    long long c = ans[i] - 1 - y;
                    for (int j = 0; j < x.size(); j++) {
                        if (!ans[x[j]]) {
                            nv.push_back(x[j]);
                        } else {
                            c -= ans[x[j]];
                        }
                    }
                    if (nv.size()) q.push_back({c, nv});
                    break;
                }
            }
        }
        auto it = min_element(q.begin(), q.end());
        if ((*it).first == 0) {
            q.erase(it);
            continue;
        }
        auto [a, b] = *it;
        if (b.size() == 1) {
            ans[b[0]] = a;
            for (int j = 0; j < q.size(); j++) {
                auto it = find(q[j].second.begin(), q[j].second.end(), b[0]);
                if (it != q[j].second.end()) {
                    q[j].second.erase(it);
                    q[j].first -= a;
                }
            }
            if (b[0] < n - 1 && !ans[b[0] + 1]) {
                auto [x, y] = transaction(ans[b[0]] - 1);
                for (int t : x) {
                    ++cnt[t];
                }
                vector<int> nv;
                long long c = ans[b[0]] - 1 - y;
                for (int j = 0; j < x.size(); j++) {
                    if (!ans[x[j]]) {
                        nv.push_back(x[j]);
                    } else {
                        c -= ans[x[j]];
                    }
                }
                if (nv.size()) q.push_back({c, nv});
            }
        } else {
            auto [b2, a2] = transaction(a / b.size());
            for (int t : b2) {
                ++cnt[t];
            }
            vector<int> nv;
            long long c = a / b.size() - a2;
            for (int j = 0; j < b2.size(); j++) {
                if (!ans[b2[j]]) {
                    nv.push_back(b2[j]);
                } else {
                    c -= ans[b2[j]];
                }
            }
            if (nv.size()) q.push_back({c, nv});
        }
    }
    for (int i = 0; i < n; i++) {
        while (cnt[i] < i) {
            transaction(ans[i]);
            ++cnt[i];
        }
    }
}

Compilation message (stderr)

souvenirs.cpp: In function 'void buy_souvenirs(int, long long int)':
souvenirs.cpp:6:19: error: 'transaction' was not declared in this scope
    6 |     auto [x, y] = transaction(p0 - 1);
      |                   ^~~~~~~~~~~
souvenirs.cpp:7:62: error: could not convert '{{<expression error>, x}}' from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, std::vector<int> > >'
    7 |     vector<pair<long long, vector<int>>> q = {{p0 - 1 - y, x}};
      |                                                              ^
      |                                                              |
      |                                                              <brace-enclosed initializer list>