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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
ll solve(ll&n,ll&m,vll&x,vll&y,vll&w)
{
ll ans=0;
ll val[n+1][n+1];
for(int i=0;i<n;i++)for(int j=0;j<=n;j++)val[i][j]=0;
for(int j=0;j<m;j++)val[x[j]][y[j]+1]+=w[j];
ll dp[n+1][n+1][3];
for(int i=0;i<n;i++)
for(int j=0;j<=n;j++)
for(int k=0;k<2;k++)
dp[i][j][k]=0;
for(int i=1;i<n;i++)
{
ll sum=0;
for(int h=0;h<=n;h++)
{
sum+=val[i-1][h];
ll aux=0;
for(int nh=h+1;nh<=n;nh++)
{
aux+=val[i][nh];
dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][0]);
dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][1]);
dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][0]);
dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][1]+aux);
}
ll og=sum;
for(int nh=0;nh<=h;nh++)
{
sum-=val[i-1][nh];
dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][0]+sum);
dp[i][h][0]=max(dp[i][h][0],dp[i-1][nh][1]);
dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][0]+sum);
dp[i][h][1]=max(dp[i][h][1],dp[i-1][nh][1]);
}
sum=og;
}
}
for(int i=0;i<n;i++)
{
for(int h=0;h<=n;h++)
{
// cout<<"For: "<<i<<' '<<h<<' '<<dp[i][h][0]<<' '<<dp[i][h][1]<<endl;
ans=max(ans,dp[i][h][0]);
ans=max(ans,dp[i][h][1]);
}
}
return ans;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W)
{
ll n=N,m=M,ans=0;
vector<ll> x(all(X)),y(all(Y)),w(all(W));
return solve(n,m,x,y,w);
}
Compilation message (stderr)
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:61:16: warning: unused variable 'ans' [-Wunused-variable]
61 | ll n=N,m=M,ans=0;
| ^~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |