Submission #1050244

#TimeUsernameProblemLanguageResultExecution timeMemory
1050244fuad27Carnival Tickets (IOI20_tickets)C++17
25 / 100
451 ms86216 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, std::vector<std::vector<int>> x) { #define int long long int n = x.size(); int m = x[0].size(); vector<pair<int,int>> s(n); vector<int> all; for(int i = 0;i<n;i++) { s[i] = pair{0, m-1}; for(int j:x[i])all.push_back(j); } sort(all.begin(), all.end()); int med = all[((int)all.size()-1)/2]; vector<int> cnt(n); long long sum=0; int ccc=0; for(int i = 0;i<n;i++) { for(int j:x[i]) { if(j < med) { ccc++; } } } for(int i = 0;i<n;i++) { for(int j:x[i]) { if(j < med or (j==med and ccc < (all.size())/2)) { if(j == med)ccc++; sum-=j; cnt[i]++; } else sum+=j; } } vector<vector<int32_t>> res(n, vector<int32_t>(m, -1)); for(int _ = 0;_<m;_++) { vector<int> idxs(n); iota(idxs.begin(), idxs.end(), 0); sort(idxs.begin(), idxs.end(), [&](int a, int b) -> bool { return cnt[a] < cnt[b]; }); vector<int> ans; for(int i = 0;i<n/2;i++) { res[idxs[i]][s[idxs[i]].second--]=_; } for(int i = n/2;i<n;i++) { // assert(cnt[idxs[i]]); cnt[idxs[i]]--; res[idxs[i]][s[idxs[i]].first++]=_; } } allocate_tickets(res); #undef int return sum; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:28:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    if(j < med or (j==med and ccc < (all.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...