#include <bits/stdc++.h>
using namespace std;
#define lf "\n"
#define ff endl
#define _ << ' ' <<
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define infos(str) do { fprintf(stderr, str"\n"); } while(0)
#define infor(str, ...) do { fprintf(stderr, str, __VA_ARGS__); } while(0)
#define infof(str, ...) do { fprintf(stderr, str"\n", __VA_ARGS__); } while(0)
#ifndef DEBUG
#undef infos
#undef infor
#undef infof
#define infos(str)
#define infor(str, ...)
#define infof(str, ...)
#endif
using ll = long long;
constexpr int LOG = 20;
constexpr int MOD = 1e9+7;
constexpr int MAXN = 1e5+7;
std::pair<std::vector<int>, long long> transaction(long long M);
void buy_souvenirs(int N, long long P0) {
if(N == 2) return (void)(transaction(P0 - 1));
if(N == 3) {
auto [q, x] = transaction(P0 - 1);
ll pay = P0 - 1 - x;
if(q.size() == 1) {
transaction(pay - 1);
transaction(pay - 1);
return;
}
transaction((pay - 1) / 2);
return;
}
int cnt = 0;
ll pay = P0;
for(int i = 1; i < N - 1; ++i) {
auto [q, x] = transaction(pay - 1);
ll pay_2 = pay - 1 - x;
if(q.size() == 2)
cnt++, pay_2--;
for(int j = 1; j < i; ++j)
transaction(pay_2);
pay = pay_2;
}
for(int i = 1; i < N - cnt; ++i)
transaction(pay - 1);
}
# | 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... |