Submission #1007436

#TimeUsernameProblemLanguageResultExecution timeMemory
1007436Ahmed57Carnival Tickets (IOI20_tickets)C++17
76 / 100
3045 ms167244 KiB
#include "bits/stdc++.h" #include "tickets.h" using namespace std; #define int long long long long find_maximum(int32_t k,vector<vector<int32_t>> x){ int n = x.size(); int m = x[0].size(); vector<vector<int32_t>> vis(n,vector<int32_t>(m,-1)); vector<vector<int32_t>> VIS(n,vector<int32_t>(m,-1)); long long fin = 0; vector<array<int,4>> pq; for(int i = 0;i<n;i++){ vector<pair<int,int>> v; for(int j = 0;j<m;j++){ v.push_back({x[i][j],j}); } sort(v.begin(),v.end()); reverse(v.begin(),v.end()); for(int j = 0;j<k;j++){ fin+=v[j].first; VIS[i][v[j].second] = 1; int lol = m-1-(k-1-j); pq.push_back({-v[j].first-v[lol].first,-v[j].second,-v[lol].second,i}); } } sort(pq.begin(),pq.end()); int ror = (n/2)*k; while(ror--){ fin+=pq.back()[0]; VIS[pq.back()[3]][-pq.back()[1]] = -1; VIS[pq.back()[3]][-pq.back()[2]] = 0; pq.pop_back(); } long long fin2 = 0; for(int i = 0;i<k;i++){ int mi[n],ma[n]; vector<array<int,5>> v; long long overall = 0; for(int j = 0;j<n;j++){ mi[j] = 1e18; ma[j] = -1e18; int MI = 0; int MA = 0; for(int w = 0;w<m;w++){ if(vis[j][w]!=-1||VIS[j][w]==-1)continue; if(VIS[j][w]==1){ if(ma[j]<x[j][w]){ ma[j] = x[j][w]; MA = w; } }else{ if(mi[j]>x[j][w]){ mi[j] = x[j][w]; MI = w; } } } v.push_back({mi[j],ma[j],MI,MA,j}); } int mim = 0; for(int j = 0;j<n;j++){ if(v[j][0]==1e18){ vis[v[j][4]][v[j][3]] = i; }if(v[j][1]==-1e18){ vis[v[j][4]][v[j][2]] = i; mim++; } } if(mim>(n/2))assert(0); for(int j = 0;j<n;j++){ if(v[j][0]==1e18||v[j][1]==-1e18)continue; if(mim<(n/2)){ vis[v[j][4]][v[j][2]] = i; mim++; }else{ vis[v[j][4]][v[j][3]] = i; } } if(mim<(n/2))assert(0); } allocate_tickets(vis); return fin; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int32_t, std::vector<std::vector<int> >)':
tickets.cpp:39:19: warning: unused variable 'overall' [-Wunused-variable]
   39 |         long long overall = 0;
      |                   ^~~~~~~
tickets.cpp:35:15: warning: unused variable 'fin2' [-Wunused-variable]
   35 |     long long fin2 = 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...