이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=1505, of=1505;
ll dp[MX][2*MX], par[MX][2*MX];
int cur[MX];
long long find_maximum(int k, std::vector<std::vector<int>> d) {
int N=d.size();
int M=d[0].size();
if(k==M) {
vector<array<int,3>> vals;
for(int i=0;i<N;i++) {
for(int j=0;j<M;j++) {
vals.push_back({d[i][j],i,j});
}
}
sort(vals.begin(),vals.end());
ll ans=0;
for(int i=0;i<N*M/2;i++) {
ans-=vals[i][0];
cur[vals[i][1]]++;
}
for(int i=N*M/2;i<N*M;i++) {
ans+=vals[i][0];
cur[vals[i][1]]++;
}
vector<pair<int,int>> v;
for(int i=0;i<N;i++)
v.push_back({cur[i]-1,i});
// for each k, we try to find N/2 nodes with largest cur_i and set it to fill in the negatives, and other N/2 o fill in the positives
vector<int> fr(N), bk(N,M-1);
vector<vector<int>> s(N,vector<int>(M,-1));
for(int x=0;x<k;x++) {
sort(v.rbegin(),v.rend());
for(int j=0;j<N/2;j++) {
auto &[y,i]=v[j];
s[i][fr[i]]=x;
fr[i]++;
y--;
}
for(int j=N/2;j<N;j++) {
auto &[y,i]=v[j];
s[i][bk[i]]=x;
bk[i]--;
}
}
allocate_tickets(s);
return ans;
}
vector<pair<int,int>> v;
for(int i=0;i<N;i++) v.push_back({d[i].front(),d[i].back()});
for(int i=0;i<MX;i++)
for(int j=0;j<2*MX;j++)
dp[i][j]=-1e18;
dp[0][0+of]=0;
for(int i=0;i<N;i++) {
for(int j=-N;j<=N;j++) {
if(dp[i][j+of]==-1e18) continue;
if(dp[i][j+of]+v[i].second>dp[i+1][j+1+of]) {
dp[i+1][j+1+of]=dp[i][j+of]+v[i].second;
par[i+1][j+1+of]=1;
}
if(dp[i][j+of]-v[i].first>dp[i+1][j-1+of]) {
dp[i+1][j-1+of]=dp[i][j+of]-v[i].first;
par[i+1][j-1+of]=-1;
}
}
}
vector<vector<int>> s(N,vector<int>(M,-1));
int cur=N, bal=0;
while(cur>0) {
if(par[cur][bal+of]>0) s[cur-1].back()=0;
else s[cur-1].front()=0;
bal-=par[cur][bal+of];
cur--;
}
allocate_tickets(s);
return dp[N][0+of];
}
# | 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... |