#include "souvenirs.h"
#include <utility>
#include <vector>
#include <iostream>
void buy_souvenirs(int N, long long P0) {
if (N == 2) {
// Subtask 1
transaction(P0 - 1);
} else if (P0 == N) {
// Subtask 2
for (long long i = N-1, k = 1; i>0; i--, k++) {
for (int j = 0; j < k; j++) {
transaction(i);
}
}
} else if (N == 3) {
// Subtask 4
std::pair<std::vector<int>, long long> res = transaction(P0-1);
long long price = P0-1-res.second;
if (res.first.size() == 1) {
transaction(price-1);
transaction(price-1);
} else {
long long special = price / 2;
transaction(special);
}
} else {
// Subtask 3
std::vector<int> cnt(N, 0);
std::vector<int> price(N, 0);
int first_price = -1;
for(int current_price = P0 - N + 1; ; current_price--) {
std::pair<std::vector<int>, long long> res = transaction(current_price);
for (int x: res.first) {
cnt[x]++;
}
if (res.second == 0 && res.first.size() == 1) {
price[res.first[0]] = current_price;
if (first_price == -1) {
first_price = current_price;
}
}
if (res.first.size() == 1 && res.first[0] == N-1 && res.second == 0) {
break;
}
}
for(int current_price = first_price+1; ; current_price++) {
std::pair<std::vector<int>, long long> res = transaction(current_price);
for (int x: res.first) {
cnt[x]++;
}
if (res.second == 0 && res.first.size() == 1) {
price[res.first[0]] = current_price;
}
if (res.first.size() == 1 && res.first[0] == 1 && res.second == 0) {
break;
}
}
for (int i=1; i<N; i++) {
for (int j = cnt[i]; j < i; j++) {
transaction(price[i]);
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |