Submission #1197866

#TimeUsernameProblemLanguageResultExecution timeMemory
1197866lrnnzCarnival Tickets (IOI20_tickets)C++17
27 / 100
302 ms51364 KiB
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <iomanip> #include "tickets.h" using namespace std; #define all(a) (a).begin(), (a).end() #define sz(a) (int)(a).size() #define ll long long #define ld long double #define ui uint64_t #define cont(set, element) ((set).find(element) != (set).end()) /********* DEBUG *********/ template <typename T> void outvec(const vector<T>& Z){ for (const T& x : Z) cout << x << ' '; cout << "\n"; } void printVariable(const any& var) { if (!var.has_value()) { cout << "null"; return; } if (var.type() == typeid(int)) { cout << any_cast<int>(var); } else if (var.type() == typeid(double)) { cout << any_cast<double>(var); } else if (var.type() == typeid(float)) { cout << any_cast<float>(var); } else if (var.type() == typeid(char)) { cout << any_cast<char>(var); } else if (var.type() == typeid(bool)) { cout << (any_cast<bool>(var) ? "true" : "false"); } else if (var.type() == typeid(string)) { cout << any_cast<string>(var); } else if (var.type() == typeid(const char*)) { cout << any_cast<const char*>(var); } else if (var.type() == typeid(long long)) { cout << any_cast<long long>(var); } else { cout << "[unknown type]"; } } template<typename... Args> void outval(Args... args) { vector<any> variables = {args...}; for (size_t i = 0; i < variables.size(); ++i) { printVariable(variables[i]); if (i != variables.size() - 1) { cout << " "; } } cout << "\n"; } #define nl "\n" #define sp << " " << /********* DEBUG *********/ const ll MOD = 1000000007; const ll inf = 1e18; const ll mxN = 1000005; struct vals { ll color,hi,lo,hi_idx,lo_idx; }; struct cmpleft { bool operator()(vals &a, vals &b){ return a.hi + a.lo < b.hi + b.lo; } }; struct cmpright{ bool operator()(vals &a, vals &b){ return a.hi + a.lo > b.hi + b.lo; } }; ll find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); priority_queue<vals, vector<vals>, cmpleft> leftq; priority_queue<vals, vector<vals>, cmpright> rightq; vector<vector<int>> alloc(n, vector<int>(m, -1)); ll ans = 0; for (int i = 0; i < n; i++){ vals push; push.color = i; push.hi = x[i][m-1]; push.lo = x[i][0]; push.hi_idx = m-1; push.lo_idx = 0; if (i < n/2){ leftq.push(push); ans -= push.lo; } else{ rightq.push(push); ans += push.hi; } } ll day = 0; while (day < k){ while (true){ ll curr = ans; vals cand = leftq.top(); leftq.pop(); curr += cand.lo + cand.hi; rightq.push(cand); cand = rightq.top(); rightq.pop(); curr -= cand.lo + cand.hi; leftq.push(cand); // cout << cand.color << "\n"; if (curr <= ans) break; ans = curr; } vector<vals> pleft, pright; while (sz(rightq) || sz(leftq)){ vals temp; if (sz(rightq)){ temp = rightq.top(); rightq.pop(); alloc[temp.color][temp.hi_idx] = day; temp.hi_idx--; temp.hi = x[temp.color][temp.hi_idx]; pright.push_back(temp); } if (sz(leftq)){ temp = leftq.top(); leftq.pop(); alloc[temp.color][temp.lo_idx] = day; temp.lo_idx++; temp.lo = x[temp.color][temp.lo_idx]; pleft.push_back(temp); } } if (++day == k) break; for (auto &x : pleft) leftq.push(x), ans -= x.lo; for (auto &x : pright) rightq.push(x), ans += x.hi; } allocate_tickets(alloc); return ans; }
#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...