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;
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
long long ans = 0;
vector<vector<int>> c(N + 1, vector<int>(N + 1));
for(int i = 0; i < M; ++i) {
c[X[i]][Y[i]] = W[i];
}
vector<vector<long long>> dp(N + 1, vector<long long>(N + 1));
dp[0][0] = 0;
for(int i = 1; i <= N; ++i) {
dp[0][i] = dp[0][i - 1] + c[1][i - 1];
}
for(int i = 1; i < N; ++i) {
dp[i][0] = 0;
for(int j = 0; j <= N; ++j) {
dp[i][0] = max(dp[i][0], dp[i - 1][j]);
}
long long preff_sum = 0, next_sum = 0;
for(int j = 1; j <= N; ++j) {
preff_sum += c[i][j - 1];
next_sum += c[i + 1][j - 1];
dp[i][j] = -0x3f3f3f3f3f3f3f3f;
for(int k = j; k <= N; ++k) dp[i][j] = max(dp[i][j], dp[i - 1][k] - preff_sum);
long long prevv_sum = 0;
for(int k = j - 1; k >= 0; --k) {
prevv_sum += c[i - 1][k];
dp[i][j] = max(dp[i][j], (i - 2 < 0 ? 0 : dp[i - 2][k]) + prevv_sum);
}
dp[i][j] += next_sum;
}
}
for(int i = 0; i <= N; ++i) ans = max(ans, dp[N - 1][i]);
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... |