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 pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int mark[2000][2000];
vector<pii>tic[2000];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
vii answer(n);
ll ans = 0;
for(int i=0;i<n;i++)answer[i].assign(m,-1);
vector<int>idx(n,k-1); //all k are minus
priority_queue<pii>pq;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
tic[i].pb({x[i][j],j});
}
sort(all(tic[i]));
for(int j=0;j<k;j++){
ans-=tic[i][j].fi;
mark[i][tic[i][j].se] = -1;
}
pq.push({tic[i][m-1].fi + tic[i][k-1].fi,i});
}
for(int i=0;i<n*k/2;i++){
ans+=pq.top().fi;
int v = pq.top().se;
int j = idx[v];
pq.pop();
mark[v][tic[v][j].se] = 0;
mark[v][tic[v][m-(k-j)].se] = 1;
idx[v]--;
j--;
if(j>=0){
pq.push({tic[v][j].fi + tic[v][m-(k-j)].fi,v});
}
}
/*
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<mark[i][j]<<" ";
}
cout<<'\n';
}*/
vector<int>colsum(m,0);
vii row(n);
for(int i=0;i<n;i++){
int z = 0;
for(int j=0;j<m;j++){
//cout<<mark[i][j]<<" ";
if(mark[i][j]){
colsum[z++]+=mark[i][j];
row[i].pb(j);
}
}
//cout<<'\n';
}
for(int i=0;i<n;i++){
vector<int>pos,neg;
for(int j=0;j<sz(row[i]);j++){
int jj = row[i][j];
if(mark[i][jj] == -1 && colsum[j] < 0)neg.pb(j);
if(mark[i][jj] == 1 && colsum[j] > 0)pos.pb(j);
}
while(!neg.empty() && !pos.empty()){
int v = neg.back();
int u = pos.back();
neg.pop_back();
pos.pop_back();
swap(row[i][v],row[i][u]);
colsum[v]+=2;
colsum[u]-=2;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<sz(row[i]);j++){
answer[i][row[i][j]] = j;
}
}
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... |