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"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
inline void chmax(int &x, int val) { x = max(x, val); }
const int MAXN = 300;
int n, m;
int pre[MAXN + 10][MAXN + 10];
int val[MAXN + 10][MAXN + 10];
int dpl[MAXN + 10][MAXN + 10][MAXN + 10];
int dpr[MAXN + 10][MAXN + 10][MAXN + 10];
int dp[MAXN + 10];
int sum(int x, int u, int d) {
if(u < d) return 0;
int res = pre[x][u];
if(d) res -= pre[x][d - 1];
return res;
}
long long max_weights(i32 N, i32 M, vector<i32> X, vector<i32> Y,
vector<i32> W) {
n = N;
m = M;
memset(pre, 0, sizeof(pre));
For(i, 0, m - 1) {
pre[X[i] + 1][Y[i] + 1] += W[i];
}
For(i, 1, n) For(j, 1, n) {
pre[i][j] += pre[i][j - 1];
}
For(l, 1, n) For(r, l + 1, n + 1) {
int mx = 0;
For(h, 0, n) {
chmax(mx, dpl[l][r - 1][h] - pre[r - 1][h]);
dpl[l][r][h] = mx + pre[r - 1][h];
}
mx = dpl[l][r - 1][n] + pre[r][n];
Forr(h, n, 0) {
chmax(mx, dpr[l][r - 1][h] + pre[r][h]);
dpr[l][r][h] = mx - pre[r][h];
}
val[l][r] = dpr[l][r][0];
}
For(i, 1, n + 1) {
For(j, 1, i) {
chmax(dp[i], dp[j - 1] + val[j][i]);
}
}
// For(x, 1, n) For(y, 1, n) {
// cerr << pre[x][y] << " \n"[y == n];
// }
// cerr << "\n";
// For(l, 1, n) For(r, 1, n) {
// cerr << val[l][r] << " \n"[r == n];
// }
return dp[n + 1];
}
/*
5 4
0 2 5
1 1 2
4 4 1
3 3 3
8
*/
# | 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... |