Submission #1316891

#TimeUsernameProblemLanguageResultExecution timeMemory
1316891madamadam3Festival (IOI25_festival)C++20
27 / 100
1199 ms2025360 KiB
#include "festival.h" #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() typedef long long ll; using pi = pair<ll, ll>; using vi = vector<ll>; struct coupon { ll t, p, idx; ll eval(ll R) { ll ans = (R-p)*t; if (R < p) ans = -4e18; else if (R >= 1e16) ans = R; return ans; } const bool operator<(const coupon &other) const { return t == other.t ? p < other.p : t < other.t; } }; vector<int> max_coupons(int A, vector<int> P, vector<int> T) { ll a = A, n = P.size(); ll required = 0, one = 0, two = 0, three = 0, four = 0; vector<coupon> coupons[5]; for (int i = 0; i < n; i++) { coupons[T[i]].push_back(coupon{T[i], P[i], i}), required += P[i]; if (T[i] == 1) one++; else if (T[i] == 2) two++; else if (T[i] == 3) three++; else four++; } // cout << one << " " << two << " " << three << " " << four << "\n"; for (int i = 1; i <= 4; i++) sort(all(coupons[i])); vector<ll> pref1; for (int i = 0; i < coupons[1].size(); i++) { if (i == 0) pref1.push_back(coupons[1][i].p); else pref1.push_back(pref1.back() + coupons[1][i].p); } vector<vector<vector<ll>>> DP(two+1, vector<vector<ll>>(three+1, vector<ll>(four+1, -4e18))), par(two+1, vector<vector<ll>>(three+1, vector<ll>(four+1, -1))); DP[0][0][0] = A; for (int x = 0; x <= two; x++) { for (int y = 0; y <= three; y++) { for (int z = 0; z <= four; z++) { if (DP[x][y][z] < 0) continue; if (x<two && DP[x+1][y][z] < coupons[2][x].eval(DP[x][y][z])) { DP[x+1][y][z] = coupons[2][x].eval(DP[x][y][z]); par[x+1][y][z] = 2; } if (y < three && DP[x][y+1][z] < coupons[3][y].eval(DP[x][y][z])) { DP[x][y+1][z] = coupons[3][y].eval(DP[x][y][z]); par[x][y+1][z] = 3; } if (z < four && DP[x][y][z+1] < coupons[4][z].eval(DP[x][y][z])) { DP[x][y][z+1] = coupons[4][z].eval(DP[x][y][z]); par[x][y][z+1] = 4; } } } } vector<int> best; for (int i = 0; i <= two; i++) { for (int j = 0; j <= three; j++) { for (int k = 0; k <= four; k++) { if (DP[i][j][k] < 0) continue; int x = i, y = j, z = k; vector<int> trail; while (par[x][y][z] != -1) { trail.push_back(par[x][y][z]); if (par[x][y][z] == 2) x--; else if (par[x][y][z] == 3) y--; else if (par[x][y][z] == 4) z--; } reverse(trail.begin(), trail.end()); x = y = z = 0; vector<int> ans; for (int u = 0; u < trail.size(); u++) { if (trail[u] == 2) ans.push_back(coupons[trail[u]][x++].idx); else if (trail[u] == 3) ans.push_back(coupons[trail[u]][y++].idx); else if (trail[u] == 4) ans.push_back(coupons[trail[u]][z++].idx); } int c1 = upper_bound(all(pref1), DP[i][j][k]) - pref1.begin(); for (int u = 0; u < c1; u++) ans.push_back(coupons[1][u].idx); if (ans.size() >= best.size()) { swap(ans, best); } } } } return best; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...