Submission #824942

#TimeUsernameProblemLanguageResultExecution timeMemory
824942pedroslreyCarnival Tickets (IOI20_tickets)C++14
27 / 100
421 ms62272 KiB
#include <bits/stdc++.h> #include "tickets.h" using namespace std; using lli = long long; vector<vector<int>> calc(vector<stack<int>> plus, vector<stack<int>> minus, int m, int k) { int n = plus.size(); vector<vector<int>> ans(n, vector<int>(m, -1)); for (int round = 0; round < k; ++round) { int cntplus = 0, cntminus = 0; auto add_plus = [&plus, &ans, &round, &cntplus](int i) { ans[i][plus[i].top()] = round; plus[i].pop(); ++cntplus; }; auto add_minus = [&minus, &ans, &round, &cntminus](int i) { ans[i][minus[i].top()] = round; minus[i].pop(); ++cntminus; }; for (int i = 0; i < n; ++i) { if (plus[i].empty()) add_minus(i); else if (minus[i].empty()) add_plus(i); else if (cntplus > cntminus) add_minus(i); else add_plus(i); } assert(cntplus == cntminus); } return ans; } lli val(vector<vector<int>> &ans, vector<vector<int>> &ms, int k) { int n = ans.size(), m = ans[0].size(); vector<vector<int>> rounds(k); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) if (ans[i][j] != -1) rounds[ans[i][j]].push_back(ms[i][j]); lli sum = 0; for (int r = 0; r < k; ++r) { sort(rounds[r].begin(), rounds[r].end()); for (int i = 0; i < n/2; ++i) sum -= rounds[r][i]; for (int i = n/2; i < n; ++i) sum += rounds[r][i]; } return sum; } lli find_maximum(int k, vector<vector<int>> ms) { int n = ms.size(), m = ms[0].size(); vector<vector<int>> ids(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) ids[i][j] = j; sort(ids[i].begin(), ids[i].end(), [&](int a, int b) { return ms[i][a] < ms[i][b]; }); } vector<int> stage(n, 0); set<pair<lli, int>> increase; auto add = [&](int i) { int x = stage[i]; auto &id = ids[i]; increase.emplace(ms[i][id[k-1-x]] + ms[i][id[m-1-x]], i); }; for (int i = 0; i < n; ++i) add(i); for (int i = 0; i < n*k/2; ++i) { auto [x, idx] = *increase.rbegin(); increase.erase(--increase.end()); ++stage[idx]; if (stage[idx] < k) add(idx); } vector<stack<int>> plus(n), minus(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < k - stage[i]; ++j) minus[i].push(ids[i][j]); for (int j = m-1; j >= m - stage[i]; --j) plus[i].push(ids[i][j]); } auto ans = calc(plus, minus, m, k); allocate_tickets(ans); return val(ans, ms, k); }

Compilation message (stderr)

tickets.cpp: In function 'lli find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:82:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |   auto [x, idx] = *increase.rbegin(); increase.erase(--increase.end());
      |        ^
#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...