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;
#define int long long int
int max_weights(int32_t N, int32_t M, vector<int32_t> X, vector<int32_t> Y, vector<int32_t> W) {
int n = N, m = M;
vector<vector<int>> c(9, vector<int>(n+1, 0));
vector<vector<vector<int>>> dp(9, vector<vector<int>>(n+1, vector<int>(2, 0))); // 0 is increasing, 1 is decreasing, increasing can go to decreasing, decreasing cant go to increasing if next to eachother
for (int i = 0; i < m; i++) {
c[Y[i]+1][X[i]] = W[i];
}
for (int j = 1; j < n; j++) {
int v = 0;
dp[0][j][0] = max(dp[0][j][0], dp[0][j-1][0]);
for (int i = 1; i < 9; i++) {
v += c[i][j];
dp[0][j][0] = max(dp[0][j][0], dp[i][j-1][0]+v);
dp[0][j][0] = max(dp[0][j][0], dp[i][j-1][1]+v);
}
for (int i = 1; i < 9; i++) {
for (int a = i; a < 9; a++) {
v = 0;
for (int b = i+1; b <= a; b++) {
v += c[b][j];
}
dp[i][j][1] = max(dp[i][j][1], dp[a][j-1][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[a][j-1][1]+v);
}
for (int a = 1; a <= i; a++) {
v = 0;
for (int b = a+1; b <= i; b++) {
v += c[b][j-1];
}
dp[i][j][0] = max(dp[i][j][0], dp[a][j-1][0]+v);
}
}
if (j == 1) {
v = 0;
for (int i = 1; i < 9; i++) {
v += c[i][j-1];
dp[i][j][0] = max(dp[i][j][0], dp[0][j-1][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[0][j-1][0]+v);
}
}
if (j-2 >= 0) {
v = 0;
for (int i = 1; i < 9; i++) {
v += c[i][j-1];
dp[i][j][0] = max(dp[i][j][0], dp[0][j-2][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[0][j-2][0]+v);
}
for (int i = 1; i < 9; i++) {
v = 0;
for (int h = 1; h <= i; h++) {
v += c[h][j-1];
}
for (int h = 1; h <= i; h++) {
dp[i][j][0] = max(dp[i][j][0], dp[h][j-2][0]+v);
dp[i][j][0] = max(dp[i][j][0], dp[h][j-2][1]+v);
dp[i][j][1] = max(dp[i][j][1], dp[h][j-2][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[h][j-2][1]+v);
}
for (int h = i+1; h < 9; h++) {
v += c[h][j];
dp[i][j][0] = max(dp[i][j][0], dp[h][j-2][0]+v);
dp[i][j][0] = max(dp[i][j][0], dp[h][j-2][1]+v);
dp[i][j][1] = max(dp[i][j][1], dp[h][j-2][0]+v);
dp[i][j][1] = max(dp[i][j][1], dp[h][j-2][1]+v);
}
}
}
}
int ans = 0;
for (int i = 0; i < 9; i++) {
ans = max(ans, dp[i][n-1][0]);
ans = max(ans, dp[i][n-1][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... |