Submission #414629

#TimeUsernameProblemLanguageResultExecution timeMemory
414629cfalasCarnival Tickets (IOI20_tickets)C++14
27 / 100
3076 ms192784 KiB
#include "tickets.h" #include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 1000000007 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) #define MINUS 2*MOD+2 #define PLUS MOD+1 long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vi> answer(n); answer.assign(n, vector<int>(m, -1)); ll ans=0; vector<multiset<ii> > minus(n), unused(n); FOR(i,n){ vii b; FOR(j,m) b.push_back({x[i][j], j}), unused[i].insert({x[i][j], j}); sort(b.begin(), b.end()); FOR(j,k){ answer[i][b[j].S] = MINUS; ans-=x[i][b[j].S]; minus[i].insert({x[i][b[j].S], b[j].S}); //unused[i].erase({x[i][b[j].S], b[j].S}); } } set<ii> maxa; FOR(i,n){ if(minus[i].size() && unused[i].size()) maxa.insert({ - ((*unused[i].rbegin()).F + (*minus[i].rbegin()).F), i}); } FOR(step, n*k/2){ ans -= (*maxa.begin()).F; ll i = (*maxa.begin()).S; maxa.erase(maxa.begin()); // change from - to unused answer[i][(*minus[i].rbegin()).S] = -1; //unused[i].insert(*minus[i].rbegin()); minus[i].erase(--minus[i].end()); // change from unused to + answer[i][(*unused[i].rbegin()).S] = PLUS; unused[i].erase(*unused[i].rbegin()); if(minus[i].size() && unused[i].size()) maxa.insert({ - ((*unused[i].rbegin()).F + (*minus[i].rbegin()).F), i}); /* cout<<ans<<endl; FOR(i,n){ FOR(j,m){ if(answer[i][j]>=MINUS) cout<<" - "; else if(answer[i][j]>=PLUS && answer[i][j]<=MINUS) cout<<" + "; else cout<<answer[i][j]<<" "; } cout<<endl; } cout<<endl;*/ } set<iii> pc; FOR(i,n){ int p=0; int lp=0; FOR(j,m) if(answer[i][j]>=PLUS && answer[i][j]<MINUS) p++, lp=j; pc.insert({{-p,i},lp}); } FOR(rnd,k){ set<int> used; int cnt=0; set<iii> pc_n; FOA(v,pc){ if(cnt==n/2) break; used.insert(v.F.S); answer[v.F.S][v.S] = rnd; iii v_n = v; v_n.F.F--; cnt++; } FOR(i,n/2) pc.erase(pc.begin()); FOA(v, pc_n) pc.insert(v); FOR(i,n) if(!used.count(i)){ ii v = *minus[i].begin(); answer[i][v.S] = rnd; minus[i].erase(minus[i].begin()); } /* FOR(i,n){ FOR(j,m) cout<<answer[i][j]<<" "; cout<<endl; }*/ } allocate_tickets(answer); return ans; }
#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...