Submission #593586

#TimeUsernameProblemLanguageResultExecution timeMemory
593586keta_tsimakuridzeCarnival Tickets (IOI20_tickets)C++14
100 / 100
2957 ms178268 KiB
#include "tickets.h" #include <vector> #include<bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> using namespace std; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<pair<int, int> > v; vector<int> l(n), r(n); vector<vector<pii> > b(n); ll ans = 0; multiset<pii> s; vector<int> LF(n); for(int i = 0; i < n; i++) { LF[i] = k; for(int j = 0; j < k; j++) { ans -= x[i][j]; s.insert({x[i][m - (k - j)] + x[i][j], i}); } } for(int i = 0; i < n * k / 2; i++) { pii x = *--s.end(); s.erase(s.find(x)); ans += x.f; --LF[x.s]; } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(j < LF[i] || j >= m - (k - LF[i])) v.push_back({x[i][j], i}); b[i].push_back({x[i][j], j}); } sort(b[i].begin(), b[i].end()); r[i] = m; } sort(v.begin(), v.end()); vector<int> cn(n); for(int i = 0; i < v.size(); i++) { if(i < v.size() / 2) cn[v[i].s]--; else cn[v[i].s]++; } vector<vector<int> > u; u.resize(n, vector<int> (m)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) u[i][j] = -1; } while(k--) { vector<pii> x; for(int i = 0; i < n; i++) x.push_back({cn[i], i}); sort(x.begin(), x.end()); for(int i = 0; i < x.size(); i++) { int id = x[i].s; if(i < x.size() / 2) { u[id][b[id][l[id]++].s] = k; cn[id]++; } else u[id][b[id][--r[id]].s] = k, cn[id]--; } } allocate_tickets(u); return ans; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for(int i = 0; i < v.size(); i++) {
      |                 ~~^~~~~~~~~~
tickets.cpp:46:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(i < v.size() / 2) cn[v[i].s]--;
      |            ~~^~~~~~~~~~~~~~
tickets.cpp:60:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int i = 0; i < x.size(); i++) {
      |                        ~~^~~~~~~~~~
tickets.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             if(i < x.size() / 2) {
      |                ~~^~~~~~~~~~~~~~
#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...