Submission #311632

#TimeUsernameProblemLanguageResultExecution timeMemory
311632tfgCarnival Tickets (IOI20_tickets)C++17
100 / 100
1031 ms62372 KiB
#include "tickets.h" #include <vector> #include <utility> #include <algorithm> #include <cassert> long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); std::vector<std::vector<int>> answer(n, std::vector<int>(m, -1)); std::vector<int> h(n, 0), l(n, k); long long tot = 0; std::vector<std::pair<int, int>> things; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { things.emplace_back(x[i][k-j-1] + x[i][m-j-1], i); tot -= x[i][j]; } } std::sort(things.rbegin(), things.rend()); for(int i = 0; i < n * k / 2; i++) { tot += things[i].first; h[things[i].second]++; l[things[i].second]--; } for(int col = 0; col < k; col++) { int U = n / 2, L = n / 2; std::vector<bool> wtf(n, false); for(int i = 0; i < n; i++) { if(h[i] == 0) { l[i]--; answer[i][l[i]] = col; wtf[i] = true; L--; } else if(l[i] == 0) { h[i]--; answer[i][m-h[i]-1] = col; wtf[i] = true; U--; } } assert(U >= 0 && L >= 0); for(int i = 0; i < n; i++) { if(!wtf[i]) { if(U) { h[i]--; answer[i][m-h[i]-1] = col; wtf[i] = true; U--; } else { l[i]--; answer[i][l[i]] = col; wtf[i] = true; L--; } } } assert(U == 0 && L == 0); } allocate_tickets(answer); return tot; }
#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...