Submission #1051501

#TimeUsernameProblemLanguageResultExecution timeMemory
1051501LittleOrangeCarnival Tickets (IOI20_tickets)C++17
27 / 100
306 ms88916 KiB
#include "tickets.h" #include <vector> #include<bits/stdc++.h> using namespace std; using ll = long long; const ll big = 1e18; struct obj{ ll v,i,j; bool operator<(const obj &o) const{ return v<o.v; } bool operator>(const obj &o) const{ return v>o.v; } }; long long find_maximum(int k, std::vector<std::vector<int>> x) { ll n = x.size(); ll m = x[0].size(); vector<vector<int>> ans(n,vector<int>(m,-1)); /*if (m == 1){ vector<ll> v; for(ll i = 0;i<n;i++) { v.push_back(x[i][0]); ans[i][0] = 0; } allocate_tickets(ans); sort(v.begin(),v.end()); ll sm = 0; for(ll i : v) sm += abs(i-v[v.size()/2]); return sm; }*/ if (k==1){ vector<deque<pair<ll,ll>>> a(n); for(ll i = 0;i<n;i++){ for(ll j = 0;j<m;j++){ a[i].push_back({x[i][j],j}); } sort(a[i].begin(),a[i].end()); } ll sm = 0; for(ll r = 0;r<k;r++){ /*for(ll i = 0;i<n;i++){ cerr << i << ":"; for(auto [v,j] : a[i]){ cerr << " " << v << "," << j; } cerr << "\n"; }*/ vector<pair<ll,ll>> ord; for(ll i = 0;i<n;i++){ ord.push_back({a[i].front().first+a[i].back().first,i}); } sort(ord.begin(),ord.end()); for(ll i = 0;i<n/2;i++){ auto [v,j] = a[ord[i].second].front();a[ord[i].second].pop_front(); ans[ord[i].second][j] = r; //cerr << r << " -> " << ord[i].second << " " << j << "\n"; sm -= v; } for(ll i = n/2;i<n;i++){ auto [v,j] = a[ord[i].second].back();a[ord[i].second].pop_back(); ans[ord[i].second][j] = r; //cerr << r << " -> " << ord[i].second << " " << j << "\n"; sm += v; } } allocate_tickets(ans); return sm; } vector<obj> v1,v2; // big small for(ll i = 0;i<n;i++){ for(ll j = 0;j<m;j++){ v1.push_back({x[i][j],i,j}); } } sort(v1.begin(),v1.end()); v2 = v1; reverse(v2.begin(),v2.end()); vector<vector<obj>> g1(n),g2(n); ll cnt = n/2*k; ll sm = 0; for(ll i = 0;i<cnt;i++){ obj o = v1.back();v1.pop_back(); sm += o.v; g1[o.i].push_back(o); } for(ll i = 0;i<cnt;i++){ obj o = v2.back();v2.pop_back(); sm -= o.v; g2[o.i].push_back(o); } ll bad = 0; for(ll i = 0;i<n;i++) if(g1[i].size()+g2[i].size()>k) bad++; while(bad){ obj o1 = {big,-1,-1}, o2 = {-big,-1,-1}; for(ll i = 0;i<n;i++) if(g1[i].size()+g2[i].size()>k){ o1 = min(o1,g1[i].back()); o2 = max(o2,g2[i].back()); } ll d1 = o1.v-v1.back().v; ll d2 = v2.back().v-o2.v; if (d1<=d2){ sm -= d1; g1[o1.i].pop_back(); g1[v1.back().i].push_back(v1.back()); v1.pop_back(); }else{ sm -= d2; g2[o2.i].pop_back(); g2[v2.back().i].push_back(v2.back()); v2.pop_back(); } bad = 0; for(ll i = 0;i<n;i++) if(g1[i].size()+g2[i].size()>k) bad++; } for(ll i = 0;i<n;i++){ for(obj o : g2[i]) g1[i].push_back(o); for(ll j = 0;j<k;j++){ ans[i][g1[i][j].j] = j; } } allocate_tickets(ans); return sm; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:93:52: warning: comparison of integer expressions of different signedness: 'std::vector<obj>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   93 |  for(ll i = 0;i<n;i++) if(g1[i].size()+g2[i].size()>k) bad++;
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~~^~
tickets.cpp:96:53: warning: comparison of integer expressions of different signedness: 'std::vector<obj>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   96 |   for(ll i = 0;i<n;i++) if(g1[i].size()+g2[i].size()>k){
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~^~
tickets.cpp:114:53: warning: comparison of integer expressions of different signedness: 'std::vector<obj>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  114 |   for(ll i = 0;i<n;i++) if(g1[i].size()+g2[i].size()>k) bad++;
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~^~
#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...