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;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const vector<T>& x);
template<class T> void OUT(const T& x) {cout << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);}
template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }
template<class H> void OUTLS(const H& h) {OUTL(h); }
template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); }
const ll INF = 1e18;
typedef tuple<ll,int,int> T;
ll find_maximum(int k, vector<vi> x) {
int n = x.size(); // colors
int m = x[0].size(); // tickets per color
int N = n*k/2;
// sort x
vector<vi> y = x;
RE(i,n) sort(all(y[i]));
vector<vi> sx(n,vi());
RE(i,n) RE(j,m) sx[i].pb(j);
RE(i,n) {
sort(all(sx[i]),[&](int a, int b) {
return x[i][a] < x[i][b];
});
}
vi negCnt; negCnt.assign(n,0);
ll ans = 0;
RE(i,n) RE(l,k) ans += y[i][m-1-l];
priority_queue<T,vector<T>,greater<T>> pq;
RE(i,n)
pq.push({y[i][0]+y[i][m-k],i,0});
RE(i,N) {
T p = pq.top(); pq.pop();
ll delta; int a, b;
tie(delta, a, b) = p;
ans -= delta;
negCnt[a]++;
b++;
if(b != k)
pq.push({y[a][b]+y[a][m-k+b],a,b});
}
// reconstruct the answer
vector<vi> answer(n,vi(m,-1));
vi nextNeg, nextPos;
RE(i,n/2) RE(j,k) nextNeg.pb(j);
RE(i,n) {
int len = negCnt[i];
vi used; used.assign(k,0);
RE(j,len)
answer[i][sx[i][j]] = nextNeg.back(), used[nextNeg.back()] = 1, nextNeg.pop_back();
RE(j,k)
if(!used[j])
nextPos.pb(j);
REP(j,m-k+len,m)
answer[i][sx[i][j]] = nextPos.back(), nextPos.pop_back();
}
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... |