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 fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> ans(n, vector<int>(m, -1));
vector<vector<ll>> dp(n, vector<ll>(k*(n/2)+1, -1e17)), ps(n, vector<ll>(m));
vector<vector<pii>> prev(n, vector<pii>(k*(n/2)+1));
for(int i=0;i<n;i++){
ps[i][0]=x[i][0];
for(int j=1;j<m;j++) ps[i][j]=ps[i][j-1]+x[i][j];
}
for(int i=0;i<=k;i++)
dp[0][i]=(ps[0][m-1]-(m-k+i-1>=0 ? ps[0][m-k+i-1] : 0))-(i ? ps[0][i-1] : 0), prev[0][i]={-1, 0};
for(int i=1;i<n;i++){
for(int j=k*(n/2);j>=0;j--){
for(int tot=0;tot<=k && j-tot>=0;tot++){
if(dp[i][j]<dp[i-1][j-tot]+(ps[i][m-1]-(m-k+tot-1>=0 ? ps[i][m-k+tot-1] : 0))-(tot ? ps[i][tot-1] : 0)){
dp[i][j]=dp[i-1][j-tot]+(ps[i][m-1]-(m-k+tot-1>=0 ? ps[i][m-k+tot-1] : 0))-(tot ? ps[i][tot-1] : 0);
prev[i][j]={i-1, j-tot};
}
}
}
}
pii curr={n-1, k*(n/2)};
int low=0, high=k-1;
vector<int> freqlow(k+1, 0), freqhigh(k+1, 0);
while(curr.fi!=-1){
pii ant=prev[curr.fi][curr.se];
while(freqlow[low]>=n/2) low++;
while(freqhigh[high]>=n/2) high--;
int diff=curr.se-ant.se;
for(int i=0;i<diff;i++) ans[curr.fi][i]=low+i, freqlow[low+i]++;
for(int i=0;i<k-diff;i++) ans[curr.fi][m-i-1]=high-i, freqhigh[high-i]++;
curr=ant;
}
allocate_tickets(ans);
return dp[n-1][k*(n/2)];
}
# | 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... |