Submission #1016737

#TimeUsernameProblemLanguageResultExecution timeMemory
1016737aykhnCarnival Tickets (IOI20_tickets)C++17
100 / 100
478 ms76120 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define inf 0x3F3F3F3F3F3F3F3F long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer(n, vector<int> (m, -1)); vector<long long> taken(n, 0); long long s = n * k / 2; priority_queue<array<int, 3>> pq; for (int i = 0; i < n; i++) { pq.push({x[i][m - 1] + x[i][k - 1], i, 0}); } while (s) { array<int, 3> y = pq.top(); pq.pop(); taken[y[1]]++; s--; if (m - y[2] - 2 >= m - k) pq.push({x[y[1]][m - y[2] - 2] + x[y[1]][k - y[2] - 2], y[1], y[2] + 1}); } vector<long long> l(n, 0), r(n, 0); for (int i = 0; i < n; i++) { r[i] = m - taken[i]; } assert(!s); vector<int> o(n); iota(o.begin(), o.end(), 0); long long res = 0; for (int t = 0; t < k; t++) { sort(o.begin(), o.end(), [&](const int &a, const int &b) { return r[a] < r[b]; }); for (int i = 0; i < o.size() / 2; i++) { res += x[o[i]][r[o[i]]]; answer[o[i]][r[o[i]]] = t; r[o[i]]++; } for (int i = o.size() / 2; i < o.size(); i++) { res -= x[o[i]][l[o[i]]]; answer[o[i]][l[o[i]]] = t; l[o[i]]++; } } allocate_tickets(answer); return res; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int i = 0; i < o.size() / 2; i++)
      |                   ~~^~~~~~~~~~~~~~
tickets.cpp:48:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for (int i = o.size() / 2; i < o.size(); i++)
      |                              ~~^~~~~~~~~~
#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...