This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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<ii> pc;
vector<set<int> > plus(n);
FOR(i,n){
int p=0;
FOR(j,m) if(answer[i][j]==PLUS) p++, plus[i].insert(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].begin())] = rnd;
plus[i].erase(plus[i].begin());
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].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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |