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>
#define ll long long
#define vt vector
#define pb push_back
#define ar array
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
using namespace std;
/*
## TAKE IT EASY ##
1. simplify
2. add new elements
3. brute force solution
4. optimize
5. start implementing
*/
// --- templates ---
// --- code ---
ll dp[305][2][2];
ll max_weights(int n, int m, vt<int> X, vt<int> Y, vt<int> W){
int h = 2;
vt<vt<ll>> a(n + 5, vt<ll>(h));
for(int i = 0; i < m; i++){
a[X[i]][1] = W[i];
}
for(int i = 0; i < n; i++){
// dp[i][0][0]
// dp[i][0][1]
// dp[i][1][0]
// dp[i][1][1]
/*
for(int j = 0; j < h; j++){
for(int k = 0; k < h; k++){
dp[i][k][0] = max(dp[i][k][0], dp[i - 1][j][k]);
}
dp[i][0][1] = max(dp[i][0][1], dp[i - 1][j][0] + a[i - 1][1 - j] + a[i + 1][1]);
dp[i][1][1] = max(dp[i][1][1], dp[i - 1][j][1] + a[i + 1][1]);
}
*/
for(int h1 = 0; h1 < h; h1++){
for(int h2 = 0; h2 < h; h2++){
for(int h3 = 0; h3 < h; h3++){
ll l = 0, r = a[i + 1][h3];
if(i == 0){
dp[i][h2][h3] = max(dp[i][h2][h3], r);
}else{
if(!(h1 || h2)){
l = a[i - 1][h3];
}
dp[i][h2][h3] = max(dp[i][h2][h3], l + dp[i - 1][h1][h2] + r);
}
}
}
}
}
ll ans = 0;
for(int h2 = 0; h2 < h; h2++){
for(int h3 = 0; h3 < h; h3++){
ans = max(ans, dp[n - 1][h2][h3]);
}
}
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... |