This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "tickets.h"
const int maxn = 1555;
int pos[maxn];
pq <pair<ll,pii> > q;
bool used[maxn];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
vector <int> tmp;
for (int j = 0; j < m; j++) tmp.pb(-1);
answer.pb(tmp);
}
ll ans = 0;
rep(i,0,n) {
rep(j,1,k+1) ans += x[i][m-j];
pos[i] = 0;
q.push({-x[i][0]-x[i][m-k],{i,0}});
}
rep(_,0,n/2*k) {
auto cur = q.top();
q.pop();
ans += cur.fi;
int tmp = cur.se.se;
pos[cur.se.fi] = tmp+1;
if (tmp+1==k) continue;
ll val = -x[cur.se.fi][tmp+1]-x[cur.se.fi][m-(k-tmp-1)];
q.push({val,{cur.se.fi,tmp+1}});
}
pq <pii> t;
rep(i,0,k) t.push({n/2,i});
rep(i,0,n) {
vector <pii> tmp;
rep(j,0,m) used[j] = false;
rep(j,0,pos[i]) {
assert(!t.empty());
pii cur = t.top();
t.pop();
if (cur.fi>1) tmp.pb({cur.fi-1,cur.se});
answer[i][j] = cur.se;
used[cur.se]=true;
}
while (!tmp.empty()) t.push(tmp.back()),tmp.pop_back();
int cur = 0;
rep(j,m-(k-pos[i]),m) {
while (used[cur]) cur++;
answer[i][j] = cur++;
}
}
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... |