Submission #576770

#TimeUsernameProblemLanguageResultExecution timeMemory
576770SlavicGCarnival Tickets (IOI20_tickets)C++17
100 / 100
814 ms54260 KiB
#include "bits/stdc++.h" #include "tickets.h" using namespace std; #define ll long long #define sz(a) (int)a.size() #define pb push_back #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define forn(i, n) for(int i=0;i < n; ++i) long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(), m = x[0].size(); std::vector<std::vector<int>> answer(n, vector<int>(m, -1)); vector<int> use_left(n, 0), r(n, m - 1); set<pair<int, int>> s; ll ans = 0; for(int i = 0; i < n; ++i) { s.insert({x[i][0] + x[i][m - k], i}); } for(int t = 0; t < n * k / 2; ++t) { int i = (*s.begin()).second; s.erase(s.begin()); if(++use_left[i] < k) { s.insert({x[i][use_left[i]] + x[i][m - k + use_left[i]], i}); } } for(int kk = 0; kk < k; ++kk) { vector<pair<int, int>> a; for(int i = 0; i < n; ++i) a.pb({use_left[i], i}); sort(rall(a)); for(int j = 0; j < n / 2; ++j) { int i = a[j].second; assert(use_left[i]); ans -= x[i][use_left[i] - 1]; answer[i][--use_left[i]] = kk; } for(int j = n / 2; j < n; ++j) { int i = a[j].second; ans += x[i][r[i]]; answer[i][r[i]--] = kk; } } allocate_tickets(answer); 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...