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>
using namespace std;
long long haha[5001][5001];
long long dp[5001][5001][3];
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
for(long long i = 0; i <= n; i++) {
for(long long j = 0; j <= n; j++) {
haha[i][j] = 0;
}
}
for(long long i = 0; i < m; i++) {
haha[x[i]+1][y[i]+1] = w[i];
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
haha[i][j]+=haha[i][j-1];
}
}
for(long long i = 0; i <= n; i++) {
dp[0][i][0] = -LLONG_MAX/2;
dp[0][i][1] = -LLONG_MAX/2;
dp[0][i][2] = -LLONG_MAX/2;
}
dp[0][0][0] = 0;
for(long long i = 1; i <= n; i++) {
long long br = 0;
for(int j = 0; j <= n; j++) {
dp[i][j][0] = -LLONG_MAX/2;
dp[i][j][1] = -LLONG_MAX/2;
dp[i][j][2] = -LLONG_MAX/2;
}
long long x = -LLONG_MAX/2;
for(long long j = n; j >= 0; j--) {
x = max(x,max(dp[i-1][j][2],dp[i-1][j][0])+haha[i][j]);
dp[i][j][2] = x-haha[i][j];
}
for(long long j = 0; j <= n; j++) {
dp[i][j][1] = max(dp[i-1][j][0],dp[i-1][j][2])+haha[i][j];
}
x = -LLONG_MAX/2;
for(long long j = 0; j <= n; j++) {
x = max(x,dp[i-1][j][1]-haha[i-1][j]);
x = max(x,dp[i-1][j][0]-haha[i-1][j]);
dp[i][j][0] = max(dp[i][j][0],x+haha[i-1][j]);
}
x = -LLONG_MAX/2;
for(long long j = n; j >= 0; j--) {
x = max(x,dp[i-1][j][1]);
dp[i][j][0] = max(dp[i][j][0],x);
}
/*for(long long j = 0; j <= n; j++) {
br+=haha[i][j];
long long sb1 = br,sb2 = 0;
dp[i][j][1] = max(dp[i][j][1],max(dp[i-1][j][0],dp[i-1][j][2])+br);
for(int k = 0; k <= n; k++) {
if(k > j) {
sb1+=haha[i-1][k];
sb2+=haha[i-1][k];
}
else {
sb1-=haha[i][k];
}
if(k <= j) {
dp[i][k][2] = max(dp[i][k][2],max(dp[i-1][j][2],dp[i-1][j][0])+sb1);
}
else {
dp[i][k][0] = max(dp[i][k][0],dp[i-1][j][0]+sb1);
}
dp[i][k][0] = max(dp[i][k][0],dp[i-1][j][1]+sb2);
}
}*/
}
long long ans = 0;
for(long long i = 0; i <= n; i++) {
ans = max(ans,max(dp[n][i][0],dp[n][i][1]));
ans = max(ans,dp[n][i][2]);
}
return ans;
}
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:29:19: warning: unused variable 'br' [-Wunused-variable]
29 | long long br = 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... |