Submission #808274

#TimeUsernameProblemLanguageResultExecution timeMemory
808274drdilyorCarnival Tickets (IOI20_tickets)C++17
27 / 100
420 ms73148 KiB
#include<bits/stdc++.h> #include "tickets.h" using namespace std; using ll = long long; const int inf = 1e9; #define debug(args...) cout << "[" << #args << "]: "; debug_out(args...); void debug_out() { cout << endl; } template<typename H, typename... T> void debug_out(H h, T... t) { cout << h << ", "; debug_out(t...); } long long find_maximum_4(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); assert(m == k); vector<tuple<int,int,int>> big; big.reserve(n * m); for (int i = 0; i < n; i++) { for (int j = 0; j < m;j++) big.push_back({x[i][j], i, j}); } stable_sort(big.begin(), big.end()); vector low(n, vector<int>(m, 0)); for (int i = 0; i < n * m / 2; i++) { low[get<1>(big[i])][get<2>(big[i])] = 1; } ll sum = 0; vector ans(n, vector<int>(m, 0)); int round_low = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (low[i][j]) { sum -= x[i][j]; ans[i][j] = round_low++; if (round_low >= m) round_low -= m; } } int round = round_low; for (int j = 0; j < m; j++) { if (!low[i][j]) { sum += x[i][j]; ans[i][j] = round++; if (round >= m) round -= m; } } } allocate_tickets(ans); return sum; } long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<tuple<int,int,int>> pos(n); for (int i = 0; i < n; i++) pos[i] = {-x[i][0], x[i][m-1], i}; sort(pos.begin(), pos.end(), [&](auto a, auto b) { return get<1>(a) - get<0>(a) > get<1>(b) - get<0>(b); }); vector ans(n, vector(m, -1)); ll sum = 0; for (int i = 0; i < n; i++) { int j = get<2>(pos[i]); if (i >= n / 2) { sum -= x[j][0]; ans[j][0] = 0; } else { sum += x[j][m-1]; ans[j][m-1] = 0; } } allocate_tickets(ans); return sum; }
#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...