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 MOD+1
#define PLUS MOD+2
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);
vector<multiset<int> > rem(n);
answer.assign(n, vector<int>(m, -1));
FOR(i,n) FOR(j,m) rem[i].insert(x[i][j]);
vii maxa, mina;
ll ans=0;
FOR(round,k){
FOR(i,n){
maxa.push_back({ - *rem[i].begin() - *(--rem[i].end()), i});
}
sort(maxa.begin(), maxa.end());
FOR(i,n){
int t = *rem[i].begin();
FOR(j,m) if(x[i][j]==t){
answer[i][j] = MINUS;
break;
}
ans -= t;
}
FOR(i,n/2){
int t = *(--rem[maxa[i].S].end());
int tp = *(rem[maxa[i].S].begin());
assert(maxa[i].F==-t-tp);
ans -= maxa[i].F;
FOR(j,m) if(x[maxa[i].S][j]==tp){
answer[maxa[i].S][j] = -1;
break;
}
FOR(j,m) if(x[maxa[i].S][j]==t){
answer[maxa[i].S][j] = PLUS;
break;
}
}
FOR(i,n){
FOR(j,m){
//cout<<answer[i][j]<<" ";
if(answer[i][j]!=-1){
rem[i].erase(x[i][j]);
}
}
//cout<<endl;
}
}
FOR(rnd,k){
vector<iii> pc(n);
FOR(i,n){
int p=0;
int lp=0;
FOR(j,m) if(answer[i][j]==PLUS) p++, lp=j;
pc[i] = {{-p,i},lp};
}
sort(pc.begin(), pc.end());
set<int> used;
FOR(i,n/2){
used.insert(pc[i].F.S);
//cout<<pc[i].F.S<<" "<<pc[i].S<<endl;
// use n/2 PLUSs
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);
}
}
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... |