// Author: Anikait Prasar
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
pair<vector<int>, ll> transaction(ll M);
void buy_souvenirs(int n, ll p0) {
if(n==2) {
transaction(p0-1);
return;
}
else if(n==3) {
auto h = transaction(p0-1);
int d = h.first.size();
ll c = h.second;
ll sum = p0-1LL-c;
if(d==1) {
// Here, sum is the value of
// 2nd element
transaction(sum-1LL);
transaction(sum-1LL);
}
if(d==2){
transaction(sum/2LL);
}
return;
}
else {
ll prev = p0;
ll last = 0;
for(int j = 1; j<n-1; j++) {
pair<vector<int>, ll> h = transaction(prev-1);
int d = h.first.size();
ll c = h.second;
if(d==2) {
prev = prev - 2;
last++;
}
else {
prev = prev - 1 - c;
}
for(int g = 0; g<j-1; g++) transaction(prev);
}
while(last < n-1) {
transaction(prev-1);
last++;
}
return;
}
// int k = 1;
// for(ll i = n-1; i>0; i--) {
// for(ll j = 0; j<k; j++) transaction(i);
// k++;
// }
}
# | 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... |