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 "fish.h"
#include <bits/stdc++.h>
typedef long long ll;
const ll INF= 1LL<<60;
using namespace std;
long long max_weights(int N, int M, std::vector<int> X, vector<int> Y,
vector<int> W) {
for(int i=0;i<M;i++){
Y[i]+=1;
}
ll rs[N+1][N+1]={};
for(int i=0;i<M;i++){
rs[X[i]][Y[i]]+=W[i];
}
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
rs[i][j+1]+=rs[i][j];
}
}
ll dp[N][3][N+1]; // (0, h[i-1]), (h[i-1] <= h[i], h[i]), (h[i-1]>h[i], h[i])
memset(dp,0,sizeof dp);
for(int i=0;i<=N;i++){
dp[1][0][i]=rs[1][i];
dp[1][1][i]=rs[0][i];
dp[1][2][i]=rs[1][N]-rs[1][i];
}
for(int i=2;i<N;i++){
for(int j=0;j<=N;j++){
dp[i][0][j]=max(dp[i-1][1][j],dp[i-1][2][j])+rs[i][j];
}
//0,k -> 1,j
ll cmax = -INF;
for(int j=0;j<=N;j++){
cmax = max(cmax,dp[i-1][0][j]+rs[i-1][j]);
dp[i][1][j]=max(dp[i][1][j],cmax-rs[i-1][j]);
}
cmax = -INF;
for(int j=N;j>=0;j--){
cmax = max(cmax,dp[i-1][0][j]);
dp[i][1][j]=max(dp[i][1][j],cmax);
}
//1,k -> 1,j
cmax = -INF;
for(int j=0;j<=N;j++){
cmax = max(cmax, dp[i-1][1][j]-rs[i-1][j]);
dp[i][1][j]=max(dp[i][1][j],cmax+rs[i-1][j]);
}
//1,k 2,k -> 2,j
cmax = -INF;
for(int j=N-1;j>=0;j--){
cmax = max(cmax, max(dp[i-1][1][j+1],dp[i-1][2][j+1])+rs[i][j+1]);
dp[i][2][j]=max(dp[i][2][j],cmax-rs[i][j]);
}
}
ll ans = 0;
/*for(int i=0;i<=N;i++){
for(int j=0;j<3;j++){
for(int k=0;k<=N;k++){
cout << dp[i][j][k] << ' ';
}
cout << endl;
}
cout << endl;
}*/
for(int j=0;j<3;j++)
for(int k=0;k<=N;k++)ans = max(ans, dp[N-1][j][k]);
return ans;
}
# | 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... |