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 rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 1e5 + 5;
const ll inf = 1e18;
ll c[N][10], dp[N][10][10];
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
int z = 0, ok1 = 1, ok2 = 1;
ll sm = 0;;
for (int i = 0; i < m; i++) {
if (x[i] & 1) ok1 = 0;
if (x[i] > 1) ok2 = 0;
sm += w[i];
}
if (ok1) return sm;
if (ok2) {
if (n == 2) {
ll sum[2];
sum[0] = sum[1] = 0;
for (int i = 0; i < m; i++) {
sum[x[i]] += w[i];
}
return max(sum[0], sum[1]);
}
int vl[2][n + 1];
memset(vl, 0, sizeof(vl));
sm = 0;
for (int i = 0; i < m; i++) {
vl[x[i]][y[i]] = w[i];
if (x[i]) sm += w[i];
}
ll ans = 0;
for (int i = 0; i <= n; i++) {
ans = max(ans, sm);
sm -= vl[1][i];
sm += vl[0][i];
}
return ans;
}
for (int i = 0; i < m; i++) {
c[x[i] + 1][y[i] + 1] = w[i];
z = max(z, y[i] + 2);
}
for (int j = 0; j < z; j++) {
for (int k = 0; k < z; k++) {
dp[0][j][k] = (k ? -inf : 0);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < z; j++) {
for (int k = 0; k < z; k++) {
for (int s = 0; s < z; s++) {
ll sum = 0;
for (int x = k + 1; x <= max(j, s); x++) {
sum += c[i][x];
}
dp[i][j][k] = max(dp[i][j][k], dp[i - 1][k][s] + sum);
}
}
}
}
ll ans = 0;
for (int i = 0; i < z; i++) {
ans = max(ans, dp[n][0][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... |