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;
using i64 = long long;
constexpr int N = 3000;
constexpr i64 inf = 1E18;
i64 dp[N + 1][N + 1][2];
i64 pre[N + 1][N + 1];
void chmax(i64 &a, i64 b) {
if (a < b) {
a = b;
}
}
long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
for (int i = 0; i < m; i++) {
pre[X[i]][Y[i] + 1] += W[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
pre[i][j + 1] += pre[i][j];
}
}
memset(dp, 190, sizeof dp);
for (int i = 0; i <= n; i++) {
dp[0][i][0] = dp[0][i][1] = 0;
}
for (int i = 1; i < n; i++) {
i64 best = -inf;
for (int k = 0; k <= n; k++) {
chmax(best, dp[i - 1][k][0] - pre[i - 1][k]);
chmax(dp[i][k][0], best + pre[i - 1][k]);
}
best = -inf;
for (int k = n; k >= 0; k--) {
chmax(best, dp[i - 1][k][1] + pre[i][k]);
chmax(dp[i][k][1], best - pre[i][k]);
}
if (i >= 2) {
best = -inf;
for (int j = n; j >= 0; j--) {
chmax(best, dp[i - 2][j][1] + pre[i - 1][j]);
chmax(dp[i][j][0], best);
}
best = -inf;
for (int j = 0; j <= n; j++) {
chmax(best, dp[i - 2][j][1]);
chmax(dp[i][j][0], best + pre[i - 1][j]);
}
}
for (int j = 0; j <= n; j++) {
chmax(dp[i][j][1], dp[i][j][0]);
}
if (i + 1 < n)
chmax(dp[i + 1][0][0], dp[i][0][1]);
}
i64 ans = 0;
for (int i = 0; i <= n; i++) {
ans = max(ans, dp[n - 1][i][1]);
}
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... |