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;
typedef long long ll;
#ifndef EVAL
#include "grader.cpp"
#endif
const int N = 305;
//~ vector<ll> dp[N], pref[N], suff[N], mx[N], id[N];
ll P[N][N], sz[N];
ll dp[N][N], pref[N][N], suff[N][N], mx[N][N];
ll tmp[N][N];
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
for(int i=0;i<m;i++){
x[i]++, y[i]++;
//~ if(x[i] > 1) dp[x[i] - 1].push_back(y[i]);
//~ if(x[i] < n) dp[x[i] + 1].push_back(y[i]);
//~ dp[x[i]].push_back(y[i]);
P[x[i]][y[i]] += w[i];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
P[i][j] += P[i][j-1];
}
}
//~ for(int i=0;i<N;i++){
//~ swap(id[i], dp[i]);
//~ id[i].push_back(0);
//~ sort(id[i].begin(), id[i].end());
//~ dp[i].resize(id[i].size());
//~ }
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
tmp[j][k] = 0;
if(j <= k){
tmp[j][k] = max(tmp[j][k], pref[k][n] + P[i-1][j] + P[i+1][j] - (i > 1 ? P[i][j] : 0) - P[i-1][j]);
} else {
tmp[j][k] = max(tmp[j][k], pref[k][k] + P[i-1][j] + P[i+1][j] - (i > 1 ? P[i][k] : 0) - P[i-1][k]);
tmp[j][k] = max(tmp[j][k], suff[k][j] + P[i-1][j] + P[i+1][j] - (i > 1 ? P[i][k] : 0) - P[i-1][j]);
tmp[j][k] = max(tmp[j][k], mx[k][j] + P[i-1][j] + P[i+1][j] - (i > 1 ? P[i][k] : 0));
}
dp[i][j] = max(dp[i][j], tmp[j][k]);
}
}
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
pref[j][k] = suff[j][k] = mx[j][k] = tmp[j][k];
mx[j][k] -= P[i][k];
}
for(int k=1;k<=n;k++){
pref[j][k] = max(pref[j][k], pref[j][k - 1]);
}
for(int k=n-1;~k;k--){
suff[j][k] = max(suff[j][k+1], suff[j][k]);
}
for(int k=j+1;k<=n;k++){
mx[j][k] = max(mx[j][k-1], mx[j][k]);
}
}
}
ll res = 0;
for(int j=0;j<=n;j++){
res = max(res, dp[n][j]);
}
return res;
}
/*
5 4
0 2 5
1 1 2
4 4 1
3 3 3
*/
# | 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... |