Submission #414640

#TimeUsernameProblemLanguageResultExecution timeMemory
414640cfalasCarnival Tickets (IOI20_tickets)C++14
100 / 100
2219 ms110916 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<int, int> 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<priority_queue<ii> > minus(n), unused(n); FOR(i,n){ vii b; FOR(j,m) b.push_back({x[i][j], j}), unused[i].push({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].push({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].top()).F + (minus[i].top()).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].top()).S] = -1; //unused[i].insert(*minus[i].rbegin()); minus[i].pop(); // change from unused to + answer[i][(unused[i].top()).S] = PLUS; unused[i].pop(); if(minus[i].size() && unused[i].size()) maxa.insert({ - ((unused[i].top()).F + (minus[i].top()).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; */ } cerr<<"HERE"<<endl; set<ii> pc; vector<queue<int> > plus(n); FOR(i,n){ int p=0; FOR(j,m) if(answer[i][j]==PLUS) p++, plus[i].push(j); pc.insert({-p,i}); } FOR(rnd,k){ set<int> used; int cnt=0; set<ii> pc_n; FOA(v,pc){ if(cnt>=n/2) break; int i = v.S; used.insert(i); answer[i][plus[i].front()] = rnd; plus[i].pop(); ii v_n = v; v_n.F++; pc_n.insert(v_n); cnt++; } //cout<<endl; FOR(i,n/2) pc.erase(pc.begin()); FOA(v, pc_n) pc.insert(v); /* 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; */ FOR(i,n){ if(!used.count(i)){ if(minus[i].empty()) continue; ii v = minus[i].top(); answer[i][v.S] = rnd; minus[i].pop(); } } /* 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...