Submission #675475

#TimeUsernameProblemLanguageResultExecution timeMemory
675475VodkaInTheJarCarnival Tickets (IOI20_tickets)C++14
27 / 100
454 ms51340 KiB
#include <bits/stdc++.h> #include <cstdio> #pragma GCC optimize("O3") #define endl '\n' using namespace std; void allocate_tickets(vector <vector <int> > r); long long find_maximum(int k, vector <vector <int> > x) { int n = (int)x.size(), m = (int)x[0].size(); vector <int> taken(n, k); long long ans = 0; int balance = 0; priority_queue <pair <int, int> > pq; for (int i = 0; i < n; i++) { for (int j = m - k; j < m; j++) ans += x[i][j]; taken[i] = k; balance += k; pq.push({-x[i][m-k]-x[i][0], i}); } while (balance > 0) { pair <int, int> curr = pq.top(); pq.pop(); ans += curr.first; balance -= 2; taken[curr.second]--; if (taken[curr.second] != 0) pq.push({-x[curr.second][m-taken[curr.second]]-x[curr.second][k-taken[curr.second]], curr.second}); } vector <vector <int> > r(n, vector <int> (m, -1)); vector <int> cnt0(k, 0), cnt1(k, 0); for (int i = 0; i < n; i++) { vector <bool> used(k, false); vector <int> poss0, poss1; for (int j = 0; j < k; j++) { if (cnt0[j] < n / 2) poss0.push_back(j); if (cnt1[j] < n / 2) poss1.push_back(j); } for (int j = 0; j < k - taken[i]; j++) { r[i][j] = poss0[j]; cnt0[poss0[j]]++; used[poss0[j]] = true; } int idx = 0; for (int j = m - taken[i]; j < m; j++) { while (used[poss1[idx]]) idx++; assert(idx < poss1.size()); used[poss1[idx]] = true; cnt1[poss1[idx]]++; r[i][j] = poss1[idx]; } } allocate_tickets(r); /* for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cout << r[i][j] << " "; cout << endl; } */ return ans; } /* int n, m, k; int main() { cin >> n >> m >> k; vector <vector <int> > x(n, vector <int> (m)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> x[i][j]; cout << find_maximum(k, x) << endl; } */

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from tickets.cpp:1:
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:59:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             assert(idx < poss1.size());
      |                    ~~~~^~~~~~~~~~~~~~
#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...