# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1252796 | TIN | 선물 (IOI25_souvenirs) | C++20 | 0 ms | 0 KiB |
#include "souvenirs.h"
#include <utility>
#include <vector>
void buy_souvenirs(int N, long long P0) {
// std::pair<std::vector<int>, long long> res = transaction(3);
if (N == 2) {
std::pair<std::vector<int>, long long> res = transaction(P0 - 1);
return;
}
std::vector<int> p(N, 0);
std::vector<int> cnt(N, 0);
p[0] = P0;
for (int i = 1; i < N; i++) {
if (cnt[i] == i) continue;
std::pair<std::vector<int>, long long> res = transaction(p[i - 1] - 1);
cnt[i]++;
p[i] = p[i - 1] - 1;
if ((int) res.first.size() > 1 || res.second > 0) p[i]--;
if ((int) res.first.size() > 1) cnt[res.first[1]]++;
while (cnt[i] < i) std::pair<std::vector<int>, long long> res = transaction(p[i]), cnt[i]++;
}
return;
}