이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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)};
vector<int> tot(n);
while(curr.fi!=-1){
pii ant=prev[curr.fi][curr.se];
int diff=curr.se-ant.se;
tot[curr.fi]=diff;
curr=ant;
}
vector<int> low(n, 0), high(n, m-1);
for(int i=0;i<k;i++){
int cnt=0;
for(int j=0;j<n;j++){
if(cnt<n/2 && tot[j]){
ans[j][low[j]]=i;
low[j]++;
cnt++;
tot[j]--;
}
else{
ans[j][high[j]]=i;
high[j]--;
}
}
}
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... |