#include "souvenirs.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll counts[2001];
ll costs[2001];
pair<vector<int>, ll> make_transaction(ll P) {
vector<int> v;
ll x;
tie(v, x) = transaction(P);
for(int g : v) counts[g]++;
return {v, x};
}
pair<vector<int>, ll> remove_known(vector<int> v, ll left) {
vector<int> v2;
v2.clear();
for(int g : v) {
if(costs[g] != -1) {
left -= costs[g];
}
else {
v2.push_back(g);
}
}
return {v2, left};
}
void try_buy(int n, ll p) {
cerr << "Try bought with " << p << endl;
ll x;
vector<int> v;
tie(v, x) = make_transaction(p);
int ret_val = v[0];
// goal: determine costs[ret_val] and everything below it.
ll left = p-x;
tie(v, left) = remove_known(v, left);
while(v.size() > 1) {
try_buy(n, left/(int)(v.size()));
tie(v, left) = remove_known(v, left);
}
assert(v[0] == ret_val);
cerr << "Determined " << ret_val << " to be " << left << endl;
costs[ret_val] = left;
if(ret_val != n-1 && costs[ret_val+1] == -1) try_buy(n, left-1);
}
void buy_souvenirs(int N, long long P0) {
for(int i = 0; i < N; i++) {
costs[i] = -1;
}
costs[0] = P0;
// pair<vector<int>, ll> res = transaction(3);
try_buy(N, P0-1);
for(int i = 1; i < N; i++) {
assert(counts[i] <= i);
assert(costs[i] != -1);
while(counts[i] < i) {
make_transaction(costs[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... |