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 <vector>
using namespace std;
long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W)
{
bool subt1=1,subt2=1,subt3=1,subt4=(N<=300);
for (int i=0;i<M;i++)
{
if (X[i]%2)
subt1=0;
if (X[i]>1)
subt2=0;
if (Y[i]!=0)
subt3=0;
if (Y[i]>8)
subt4=0;
}
if (subt1)
{
long long sm=0;
for (int i=0;i<M;i++)
sm+=W[i];
return sm;
}
if (subt2)
{
long long sm[N]={};
long long val[N][2]={};
for (int i=0;i<M;i++)
val[Y[i]][X[i]]=W[i];
sm[0]=val[0][1];
for (int i=1;i<N;i++)
sm[i]=sm[i-1]+val[i][1];
long long ans=sm[N-1];
long long x=0;
for (int i=0;i<N;i++)
{
x+=val[i][0];
if (N>2)
ans=max(ans,x+sm[N-1]-sm[i]);
}
ans=max(ans,x);
return ans;
}
if (subt3)
{
long long dp[N][2]={};
int val[N]={};
for (int i=0;i<M;i++)
val[X[i]]=W[i];
dp[0][0]=0,dp[0][1]=val[0];
long long ans=0;
long long mx=0;
for (int i=1;i<N;i++)
{
if (i>1)
dp[i][0]=mx+val[i];
if (i<N-1)
dp[i][1]=max(dp[i][0],dp[i-1][0]+val[i]);
mx=max(mx,max(dp[i-1][0],dp[i-1][1]));
ans=max(ans,max(dp[i][0],dp[i][1]));
}
return ans;
}
if (N<=3000)
{
vector<vector<vector<long long>>>dp(2,vector<vector<long long>>(N,vector<long long>(N,0)));
long long val[N][N]={};
for (int i=0;i<M;i++)
val[X[i]][Y[i]]=W[i];
long long pre[N][N]={};
for (int i=0;i<N;i++)
{
pre[i][0]=val[i][0];
for (int j=1;j<N;j++)
pre[i][j]=pre[i][j-1]+val[i][j];
}
long long mx[N]={};
long long ans=0;
for (int i=0;i<N;i++)
dp[1][0][i]=pre[0][i];
for (int i=0;i<N;i++)
dp[0][1][i]=pre[1][i];
mx[0]=pre[0][N-1];
for (int i=1;i<N;i++)
{
for (int j=0;j<N;j++)
{
if (i>1)
{
dp[0][i][j]=mx[i-2]+pre[i][j];
dp[0][i][j]=max(dp[0][i][j],pre[i][j]+pre[i-1][N-1]-pre[i-1][j]);
}
if (i>2)
dp[0][i][j]=max(dp[0][i][j],mx[i-3]+pre[i][j]+pre[i-1][N-1]-pre[i-1][j]);
if (i+1<N)
{
dp[1][i][j]=max(dp[0][i][j],dp[0][i-1][N-1]+pre[i][j]);
if (j>0)
dp[1][i][j]=max(dp[1][i][j],dp[1][i-1][j-1]+val[i][j]);
}
}
mx[i]=max(mx[i-1],max(dp[0][i][N-1],dp[1][i][N-1]));
}
for (int i=0;i<N;i++)
for (int j=0;j<N;j++)
ans=max(ans,max(dp[0][i][j],dp[1][i][j]));
return ans;
}
return 0;
}
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:5:34: warning: variable 'subt4' set but not used [-Wunused-but-set-variable]
5 | bool subt1=1,subt2=1,subt3=1,subt4=(N<=300);
| ^~~~~
# | 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... |