Submission #1091663

#TimeUsernameProblemLanguageResultExecution timeMemory
1091663efishelCarnival Tickets (IOI20_tickets)C++17
11 / 100
2 ms860 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector <ll>; using ii = pair <ll, ll>; using vii = vector <ii>; using vi = vector <int>; using vvi = vector <vi>; ll find_maximum (int k, vvi x) { ll n = x.size(), m = x[0].size(); vll l(n, 0), r(n, m-1); vvi answer(n, vi(m, -1)); vector <pair <ll, ii> > th; for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { th.push_back({ x[i][j], { i, j }}); } } ll ans = 0; sort(th.rbegin(), th.rend()); vector <vll> is1(n, vll{}), is0(n, vll{}); ll off = 0; for (ll idk = 0; idk < k*n/2+off; idk++) { auto [i, j] = th[idk].second; if (is1[i].size() == k) { off++; continue; } is1[i].push_back(j); ans += th[idk].first; } off = 0; for (ll idk = n*m-1; idk >= n*m-k*n/2-off; idk--) { auto [i, j] = th[idk].second; if (is1[i].size()+is0[i].size() == k) { off++; continue; } is0[i].push_back(j); ans -= th[idk].first; } for (ll ik = 0; ik < k; ik++) { ll c0 = n/2, c1 = n/2; for (ll i = 0; i < n; i++) { if (c0 == 0) { assert(is1[i].size()); answer[i][is1[i].back()] = ik; is1[i].pop_back(); c1--; continue; } if (c1 == 0) { assert(is0[i].size()); answer[i][is0[i].back()] = ik; is0[i].pop_back(); c0--; continue; } if (is0[i].size()) { answer[i][is0[i].back()] = ik; is0[i].pop_back(); c0--; continue; } if (is1[i].size()) { answer[i][is1[i].back()] = ik; is1[i].pop_back(); c1--; continue; } } assert(c0 == 0 && c1 == 0); } allocate_tickets(answer); return ans; }

Compilation message (stderr)

tickets.cpp: In function 'll find_maximum(int, vvi)':
tickets.cpp:27:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |         if (is1[i].size() == k) { off++; continue; }
      |             ~~~~~~~~~~~~~~^~~~
tickets.cpp:34:41: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         if (is1[i].size()+is0[i].size() == k) { off++; continue; }
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
#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...