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});
}
}
FOR(step, n*k/2){
vii maxa;
FOR(i,n){
if(minus[i].size() && unused[i].size())
maxa.push_back({ - ((*unused[i].rbegin()).F + (*minus[i].rbegin()).F), i});
}
sort(maxa.begin(), maxa.end());
ans -= maxa[0].F;
ll i = maxa[0].S;
// 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());
/*
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;*/
}
FOR(rnd,k){
vector<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.push_back({{-p,i},lp});
}
sort(pc.begin(), pc.end());
set<int> used;
FOR(i,n/2){
used.insert(pc[i].F.S);
answer[pc[i].F.S][pc[i].S] = rnd;
}
FOR(i,n) if(!used.count(i)){
bool f = false;
FOR(j,m) if(answer[i][j]>=MINUS){
answer[i][j] = rnd;
f = true;
break;
}
assert(f);
}
/*
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... |