Submission #1254872

#TimeUsernameProblemLanguageResultExecution timeMemory
1254872TimoshSouvenirs (IOI25_souvenirs)C++20
7 / 100
12 ms420 KiB
#include <bits/stdc++.h> #include "souvenirs.h" using namespace std; #define ll long long void buy_souvenirs(int n, long long P0) { vector<ll> p(n), used(n); p[0] = P0; vector<pair<vector<int>, ll>> mp; map<ll, pair<vector<int>, ll>> ehh; auto ch = [&](ll x) -> pair<vector<int>, ll> { if (ehh.count(x)) return ehh[x]; pair<vector<int>, ll> hm = transaction(x); for (auto &i : hm.first) used[i]++; hm.second = x - hm.second; mp.push_back(hm); return ehh[x] = hm; }; auto rec = [&](auto rec, int i) -> void { if (i == n - 1) return; while (1) { pair<vector<int>, ll> cur; ll s = p[i] - 1; int sz = 2; while (1) { cur = ch(s); s = cur.second; sz = cur.first.size(); for (auto &i : cur.first) { s -= p[i]; sz -= p[i] != 0; } if (sz <= 1) break; s = s / sz; } p[cur.first[0]] = s, rec(rec, cur.first[0]); if (cur.first[0] == i + 1) return; for (auto &x : mp) { int s = x.second, c = 0, j = 0; for (auto &i : x.first) { if (p[i] == 0) c++, j = i; s -= p[i]; } if (c == 1) p[j] = s; } } }; rec(rec, 0); for (int i = 0; i < n; i++) for (int j = used[i]; j < i; j++) transaction(p[i]); return; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...