Submission #1230815

#TimeUsernameProblemLanguageResultExecution timeMemory
1230815PlayVoltzCarnival Tickets (IOI20_tickets)C++20
27 / 100
359 ms87028 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define mp make_pair #define pb push_back #define fi first #define se second map<int, map<int, int> > cc; bool custom(pair<int, pii> a, pair<int, pii> b){ if (a.fi==b.fi)return cc[a.se.fi][a.fi]>cc[b.se.fi][b.fi]; return a.fi<b.fi; } long long find_maximum(int k, vector<vector<int> > x){ cc.clear(); int n=x.size(), m=x[0].size(); long long res=0; vector<int> l(n, k-1), r(n, m-1); vector<vector<int> > ans(n, vector<int>(m, -1)), t(n, vector<int>(m, 0)), got(n, vector<int>(m, 0)); vector<vector<pii> > vect(n, vector<pii>(m)); priority_queue<pii> pq; for (int i=0; i<n; ++i){ for (int j=0; j<m; ++j)vect[i][j]=mp(x[i][j], j); sort(vect[i].begin(), vect[i].end()); for (int j=0; j<k; ++j)res-=vect[i][j].fi, t[i][vect[i][j].se]=-1; pq.push(mp(vect[i][l[i]].fi+vect[i][r[i]].fi, i)); } for (int i=0; i<n*k/2; ++i){ pii c=pq.top(); pq.pop(); res+=c.fi; t[c.se][vect[c.se][l[c.se]].se]=0; t[c.se][vect[c.se][r[c.se]].se]=1; --l[c.se]; --r[c.se]; if (l[c.se]>=0)pq.push(mp(vect[c.se][l[c.se]].fi+vect[c.se][r[c.se]].fi, c.se)); } vector<pair<int, pii> > low, high; for (int i=0; i<n; ++i)for (int j=0; j<m; ++j){ if (t[i][j]==-1)low.pb(mp(x[i][j], mp(i, j))), ++cc[i][x[i][j]]; else if (t[i][j])high.pb(mp(x[i][j], mp(i, j))), ++cc[i][x[i][j]]; } sort(low.begin(), low.end(), custom); sort(high.begin(), high.end(), custom); vector<int> count(n, 0), tt(k, 0); for (auto c:low){ while (count[c.se.fi]<k&&tt[count[c.se.fi]]>=n/2)++count[c.se.fi]; if (count[c.se.fi]<k&&tt[count[c.se.fi]]<n/2)ans[c.se.fi][c.se.se]=count[c.se.fi], got[c.se.fi][count[c.se.fi]]=1, ++tt[count[c.se.fi]]; ++count[c.se.fi]; } count.assign(n, 0); for (auto c:high){ while (count[c.se.fi]<k&&got[c.se.fi][count[c.se.fi]])++count[c.se.fi]; if (count[c.se.fi]<k&&!got[c.se.fi][count[c.se.fi]])ans[c.se.fi][c.se.se]=count[c.se.fi]; ++count[c.se.fi]; } allocate_tickets(ans); 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...