Submission #1032941

#TimeUsernameProblemLanguageResultExecution timeMemory
1032941ZicrusCarnival Tickets (IOI20_tickets)C++17
27 / 100
361 ms82108 KiB
#include <bits/stdc++.h> #include "tickets.h" using namespace std; typedef long long ll; ll sub1(int k, vector<vector<int>> x) { vector<int> s(x.size()); for (int i = 0; i < x.size(); i++) s[i] = x[i][0]; sort(s.begin(), s.end()); ll median = s[s.size() / 2]; ll sum = 0; for (auto &e : s) sum += abs(e - median); allocate_tickets(vector<vector<int>>(s.size(), vector<int>(1))); return sum; } ll sub2(int k, vector<vector<int>> x) { ll n = x.size(), m = x[0].size(); vector<vector<int>> res(n, vector<int>(m, -1)); ll sum = 0; vector<ll> front(n, 0), back(n, m-1); while (k--) { vector<pair<ll, ll>> avgId(n); for (int i = 0; i < n; i++) { avgId[i] = {x[i][front[i]] + x[i][back[i]], i}; } sort(avgId.begin(), avgId.end()); vector<ll> choices(n); ll median = 0; for (int i = 0; i < n/2; i++) { choices[i] = x[avgId[i].second][front[avgId[i].second]]; res[avgId[i].second][front[avgId[i].second]] = k; front[avgId[i].second]++; median = max(median, choices[i]); } for (int i = n/2; i < n; i++) { choices[i] = x[avgId[i].second][back[avgId[i].second]]; res[avgId[i].second][back[avgId[i].second]] = k; back[avgId[i].second]--; } for (auto &e : choices) sum += abs(e - median); } allocate_tickets(res); return sum; } ll find_maximum(int k, vector<vector<int>> x) { return sub2(k, x); }

Compilation message (stderr)

tickets.cpp: In function 'll sub1(int, std::vector<std::vector<int> >)':
tickets.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = 0; i < x.size(); i++) s[i] = x[i][0];
      |                     ~~^~~~~~~~~~
#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...