| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1282087 | lukasuliashvili | Festival (IOI25_festival) | C++20 | 0 ms | 0 KiB |
#include <vector>
#include <algorithm>
std::vector<int> max_coupons(int A, std::vector<int> P, std::vector<int> T) {
int N = P.size();
bool is_sub1 = std::all_of(T.begin(), T.end(), [](int t) { return t == 1; });
if (is_sub1) {
std::vector<std::pair<int, int>> items;
for (int i = 0; i < N; ++i) items.emplace_back(P[i], i);
std::sort(items.begin(), items.end());
std::vector<int> res;
for (auto& [price, idx] : items) {
if (A >= price) {
A -= price;
res.push_back(idx);
} else break;
}
return res;
}
if (N <= 20) {
std::vector<int> indices(N);
for (int i = 0; i < N; ++i) indices[i] = i;
std::vector<int> best;
do {
int tokens = A;
std::vector<int> used;
for (int i = 0; i < N; ++i) {
int idx = indices[i];
if (tokens >= P[idx]) {
tokens = (tokens - P[idx]) * T[idx];
used.push_back(idx);
} else break;
}
if (used.size() > best.size()) best = used;
} while (std::next_permutation(indices.begin(), indices.end()));
return best;
}
std::vector<int> result, current_path;
std::vector<bool> used(N, false);
std::function<void(int)> dfs = [&](int tokens) {
if (current_path.size() > result.size()) result = current_path;
for (int i = 0; i < N; ++i) {
if (!used[i] && tokens >= P[i]) {
used[i] = true;
current_path.push_back(i);
dfs((tokens - P[i]) * T[i]);
current_path.pop_back();
used[i] = false;
}
}
};
dfs(A);
return result;
}
