Submission #1255763

#TimeUsernameProblemLanguageResultExecution timeMemory
1255763madamadam3Souvenirs (IOI25_souvenirs)C++20
0 / 100
0 ms412 KiB
#include "souvenirs.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using pi = pair<int, int>; #define FOR(i, a, b) for (int i = a; i < b; i++) #define ROF(i, a, b) for (int i = a; i >= b; i--) #define each(a, x) for (auto &a : x) #define all(x) (x).begin(), (x).end() #define bg(x) (x).begin() #define en(x) (x).end() #define rev(x) reverse(all(x)) #define sz(x) int((x).size()) #define srt(x) sort(all(x)) #define cnt(a, x) count(all(x), a) #define trace(x) each(a, (x)) cout << a << " " #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound struct DSU { int n; vi par, siz; DSU() {}; DSU(int N) { n = N; par.resize(n); siz.assign(n, 1); iota(all(par), 0); } int find(int v) { if (par[v] == v) return v; return par[v] = find(par[v]); } void unite(int a, int b) { a = find(a); b = find(b); if (a != b) { if (siz[a] < siz[b]) swap(a, b); par[b] = a; siz[a] += siz[b]; } } }; using R = pair<vi, ll>; const ll INF = 4e18; int n; vi bought; vl price, low, high; R transact(ll money) { auto res = transaction(money); for (auto &el : res.first) { bought[el]++; } return res; } vl actual = {89, 55, 34, 21, 13, 8, 5, 3, 2, 1}; void buy_souvenirs(int N, ll P0) { n = N; bought.assign(n, 0); price.assign(n, -1); low.assign(n, INF); high.assign(n, -INF); price[0] = P0; low[0] = P0; high[0] = P0; FOR(i, 1, n) { // assume we always know price[i-1] low[i] = (low[i-1] + 1) / 2; high[i] = (2 * high[i-1]) / 3; } auto r1 = transact(high[n-1]); if (sz(r1.first) != 1) exit(1); if (r1.first[0] != n-1 && r1.first[0] != n-2) exit(2); int start = n - 2; if (r1.first[0] == n-1) { price[n-1] = high[n-1] - r1.second; } else { price[n-2] = high[n-1] - r1.second; auto r2 = transact(price[n-2] - 1); price[n-1] = (price[n-2]-1) - r2.second; start = n - 3; } ROF(i, start, 1) { ll pv = price[i+1]; auto r = transact(2*pv); ll cost = (2*pv) - r.second; for (auto &el : r.first) { if (price[el] == -1) continue; cost -= price[el]; } price[i] = cost; } // cerr << "Actual:\tLow:\tHigh:\n"; // FOR(i, 0, n) { // cerr << actual[i] << "\t" << low[i] << "\t" << high[i] << "\n"; // } // while (bought[n-1] < n-1) { // transact(price[n-2] - 1); // } FOR(i, 0, n) { if (price[i] == -1) continue; while (bought[i] < i) { transact(price[i]); } } }
#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...