Submission #782715

#TimeUsernameProblemLanguageResultExecution timeMemory
782715JosiaCarnival Tickets (IOI20_tickets)C++17
100 / 100
1120 ms155836 KiB
#include "tickets.h" #include <vector> #include <bits/stdc++.h> using namespace std; #define int long long int find_maximum(signed k, std::vector<std::vector<signed>> x) { int colors = x.size(); int ticketsPerColor = x[0].size(); priority_queue<array<int, 4>> pq; // val, col, indO, indN; int res = 0; for (int i=0; i<colors; i++) { for (int j = 0; j<k; j++) { res -= x[i][j]; pq.push({x[i][j] + x[i][ticketsPerColor-(k-j)], i, j, ticketsPerColor-(k-j)}); } } vector<pair<int, int>> numused(colors); for (int i = 0; i<colors; i++) numused[i].second = i; for (int i = 0; i<colors*k/2; i++) { res += pq.top()[0]; numused[pq.top()[1]].first++; // used[pq.top()[1]][pq.top()[2]] = 0; // used[pq.top()[1]][pq.top()[3]] = 2; pq.pop(); } set<pair<int, int>> blub; for (auto i: numused) blub.insert(i); vector<pair<int, int>> bounds(colors, {0, ticketsPerColor-1}); vector<vector<signed>> ass(colors, vector<signed>(ticketsPerColor, -1)); for (int i = 0; i<k; i++) { vector<pair<int, int>> round; for (int j = 0; j<colors/2; j++) { round.push_back(*blub.begin()); blub.erase(blub.begin()); ass[round.back().second][bounds[round.back().second].first] = i; bounds[round.back().second].first++; } for (int j = 0; j<colors/2; j++) { round.push_back(*blub.rbegin()); blub.erase(*blub.rbegin()); ass[round.back().second][bounds[round.back().second].second] = i; bounds[round.back().second].second--; round.back().first--; } for (auto i: round) blub.insert(i); } allocate_tickets(ass); return res; }
#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...