Submission #789686

#TimeUsernameProblemLanguageResultExecution timeMemory
789686FEDIKUSCarnival Tickets (IOI20_tickets)C++17
100 / 100
561 ms76052 KiB
#include "tickets.h" #include <bits/stdc++.h> using ll = long long; using namespace std; ll find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer; for (int i = 0; i < n; i++) { vector<int> row(m); for (int j = 0; j < m; j++) { row[j] = -1; } answer.push_back(row); } ll res=0; for(int i=0;i<n;i++){ for(int j=0;j<k;j++){ res-=x[i][j]; } } vector<int> klkp(n,0); priority_queue<pair<int,int> > pq; for(int i=0;i<n;i++) pq.push({x[i][m-1]+x[i][k-1],i}); for(int i=0;i<n*k/2;i++){ //for(int j=0;j<n;j++){ // if(klkp[j]==k) continue; // maxi=max(maxi,{x[j][m-1-klkp[j]]+x[j][k-1-klkp[j]],j}); //} pair<int,int> maxi=pq.top(); pq.pop(); res+=maxi.first; klkp[maxi.second]++; // if(klkp[maxi.second]==k) continue; pq.push({x[maxi.second][m-1-klkp[maxi.second]]+x[maxi.second][k-1-klkp[maxi.second]],maxi.second}); } vector<int> uzeop(n,0); bool uspeo=true; for(int i=0;i<k;i++){ vector<pair<int,int> > sta(n,{0,0}); for(int j=0;j<n;j++){ sta[j]={-klkp[j]+uzeop[j],j}; } vector<bool> uzimamp(n,false); sort(sta.begin(),sta.end()); for(int i=0;i<n/2;i++){ uzimamp[sta[i].second]=true; } for(int j=0;j<n;j++){ if(uzimamp[j]){ answer[j][m-1-uzeop[j]]=i; uzeop[j]++; }else{ answer[j][i-uzeop[j]]=i; } } } for(int i=0;i<n;i++) if(uzeop[i]!=klkp[i]) uspeo=false; if(!uspeo) exit(-1); allocate_tickets(answer); return res; }
#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...