Submission #1007438

#TimeUsernameProblemLanguageResultExecution timeMemory
1007438Ahmed57Carnival Tickets (IOI20_tickets)C++17
100 / 100
702 ms190080 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; priority_queue<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({-v[j].first-v[lol].first,-v[j].second,-v[lol].second,i}); } } int ror = (n/2)*k; while(ror--){ fin+=pq.top()[0]; VIS[pq.top()[3]][-pq.top()[1]] = -1; VIS[pq.top()[3]][-pq.top()[2]] = 0; pq.pop(); } vector<int> pos[n],neg[n]; for(int i = 0;i<n;i++){ for(int j = 0;j<m;j++){ if(VIS[i][j]==1){ pos[i].push_back(j); }else if(VIS[i][j]==0){ neg[i].push_back(j); } } reverse(neg[i].begin(),neg[i].end()); } long long fin2 = 0; for(int i = 0;i<k;i++){ int mim = 0; for(int j = 0;j<n;j++){ if(pos[j].size()==0){ vis[j][neg[j].back()] = i; mim++; continue; }if(neg[j].size()==0){ vis[j][pos[j].back()] = i; continue; } } for(int j = 0;j<n;j++){ if(pos[j].size()==0){ neg[j].pop_back();continue; }else if(neg[j].size()==0){ pos[j].pop_back();continue; }else{ if(mim<(n/2)){ vis[j][neg[j].back()] = i; neg[j].pop_back(); mim++; }else{ vis[j][pos[j].back()] = i; pos[j].pop_back(); mim++; } } } } 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:45:15: warning: unused variable 'fin2' [-Wunused-variable]
   45 |     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...