Submission #928116

#TimeUsernameProblemLanguageResultExecution timeMemory
928116EJIC_B_KEDAXCarnival Tickets (IOI20_tickets)C++17
27 / 100
521 ms54184 KiB
#include <bits/stdc++.h> #include "tickets.h" using ll = long long; using namespace std; mt19937_64 mt(time(nullptr)); ll find_maximum(int k, vector<vector<int>> t) { int n = t.size(), m = t[0].size(); vector<int> all; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { all.push_back(t[i][j]); } } sort(all.begin(), all.end()); int middle = all[all.size() / 2]; ll res = 0; vector<pair<ll, int>> a(n); vector<int> bg(n, 0), end(n, m - 1); vector<vector<int>> s(n, vector<int>(m, -1)); for (int i = 0; i < n; i++) { a[i].first = 0; a[i].second = i; for (int j = 0; j < m; j++) { t[i][j] -= middle; } } for (int st = 0; st < k; st++) { vector<pair<int, int>> l, r; for (int i = 0; i < n; i++) { if (abs(t[i][bg[i]]) > abs(t[i][end[i]])) { if (t[i][end[i]] < 0) { l.emplace_back(INT32_MAX, i); } else if (!t[i][end[i]]) { l.emplace_back(INT32_MAX / 2, i); } else { l.emplace_back(abs(abs(t[i][bg[i]]) - abs(t[i][end[i]])), i); } } else { if (t[i][bg[i]] > 0) { r.emplace_back(INT32_MAX, i); } else if (!t[i][bg[i]]) { r.emplace_back(INT32_MAX / 2, i); } else { r.emplace_back(abs(abs(t[i][bg[i]]) - abs(t[i][end[i]])), i); } } } sort(l.begin(), l.end(), greater<>()); sort(r.begin(), r.end(), greater<>()); set<int> li, ri; for (auto [w, i] : l) { li.insert(i); } for (auto [w, i] : r) { ri.insert(i); } while (l.size() > n / 2) { li.erase(l.back().second); ri.insert(l.back().second); l.pop_back(); } while (r.size() > n / 2) { ri.erase(r.back().second); li.insert(r.back().second); r.pop_back(); } vector<int> nw; assert(li.size() == n / 2); assert(ri.size() == n / 2); for (int i : li) { s[i][bg[i]] = st; // assert(t[i][bg[i]] <= 0); nw.push_back(t[i][bg[i]++]); } for (int i : ri) { s[i][end[i]] = st; // assert(t[i][end[i]] >= 0); nw.push_back(t[i][end[i]--]); } sort(nw.begin(), nw.end()); for (int i : nw) { res += abs(i); } // assert(0 >= nw[n / 2 - 1] && 0 <= nw[n / 2]); } allocate_tickets(s); return res; }

Compilation message (stderr)

tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:61:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |         while (l.size() > n / 2) {
      |                ~~~~~~~~~^~~~~~~
tickets.cpp:66:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |         while (r.size() > n / 2) {
      |                ~~~~~~~~~^~~~~~~
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:72:26: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |         assert(li.size() == n / 2);
      |                ~~~~~~~~~~^~~~~~~~
tickets.cpp:73:26: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   73 |         assert(ri.size() == n / 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...