Submission #1255129

#TimeUsernameProblemLanguageResultExecution timeMemory
1255129otariusFestival (IOI25_festival)C++20
100 / 100
121 ms91308 KiB
#include "festival.h" #include <bits/stdc++.h> #include <bits/extc++.h> using namespace __gnu_pbds; using namespace std; // #pragma GCC optimize("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ff first #define sc second #define pb push_back #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define ull unsigned long long #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count()); #define int long long // #define int unsigned long long // #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> // #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update> // const ll mod = 1e9 + 7; // const ll mod = 998244353; const ll inf = 1e9; const ll biginf = 1e18; // const int maxN; bool comp(array<int, 3> a, array<int, 3> b) { return a[0] * a[1] * b[1] + b[0] * b[1] < b[0] * a[1] * b[1] + a[0] * a[1]; } vector<int32_t> max_coupons(int32_t A, vector<int32_t> p, vector<int32_t> t) { ll a = A; vector<array<int, 3>> v, tv; vector<int> pos, pref; for (int i = 0; i < p.size(); i++) { if (t[i] > 1) v.pb({p[i], t[i], i}); else pos.pb(i); } sort(all(v), comp); sort(all(pos), [&](int a, int b) { return p[a] < p[b]; }); pref.resize(pos.size()); for (int i = 0; i < pos.size(); i++) { pref[i] = p[pos[i]]; if (i > 0) pref[i] += pref[i - 1]; } vector<int32_t> ans; for (int i = 0; i < v.size(); i++) { if (1LL * (a - v[i][0]) * v[i][1] >= a) { a = min(1LL * (a - v[i][0]) * v[i][1], 200000000000000LL); ans.pb(v[i][2]); } else tv.pb(v[i]); } v = tv; int n = v.size(); ll dp[n + 1][50]; for (int i = 0; i <= n; i++) for (int j = 0; j < 50; j++) dp[i][j] = -1; dp[0][0] = a; for (int i = 0; i < n; i++) { for (int j = 0; j < 50; j++) dp[i + 1][j] = dp[i][j]; for (int j = 0; j < 49; j++) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], 1LL * (dp[i][j] - v[i][0]) * v[i][1]); } int mx = -1, cnt, cur; for (int i = 0; i < 50; i++) { if (dp[n][i] < 0) continue; cur = upper_bound(all(pref), dp[n][i]) - pref.begin(); if (cur + i >= mx) { mx = cur + i; cnt = i; } } vector<int> tmp; int tmp1 = mx - cnt; for (int i = n - 1; i >= 0; i--) { if (dp[i + 1][cnt] != dp[i][cnt]) tmp.pb(v[i][2]), cnt--; } reverse(all(tmp)); for (int i : tmp) ans.pb(i); for (int i = 0; i < tmp1; i++) ans.pb(pos[i]); return ans; } // int32_t main() { // int N, A; // assert(2 == scanf("%lld %lld", &N, &A)); // std::vector<int32_t> P(N), T(N); // for (int i = 0; i < N; i++) // assert(2 == scanf("%d %d", &P[i], &T[i])); // fclose(stdin); // std::vector<int32_t> R = max_coupons(A, P, T); // int S = R.size(); // printf("%lld\n", S); // for (int i = 0; i < S; i++) // printf("%s%d", (i == 0 ? "" : " "), R[i]); // printf("\n"); // fclose(stdout); // return 0; // }
#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...