#include "fish.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e9;
int max_weights(int32_t N, int32_t M, vector<int32_t> X,vector<int32_t> Y, vector<int32_t> W) {
assert(N <= 300);
vi pos[N+2];
vi stuf[N+1];
for (int i=0;i<M;i++) X[i]++,Y[i]++;
for (int i = 0;i<M;i++) stuf[X[i]].push_back(Y[i]);
pos[0] = {0};
pos[N+1] = {0};
for (int i = 1;i<=N;i++) {
if (i>1) for (auto it : stuf[i-1]) pos[i].push_back(it);
if (i<N) for (auto it : stuf[i+1]) pos[i].push_back(it);
pos[i].push_back(0);
sort(all(pos[i]));
pos[i].erase(unique(all(pos[i])),pos[i].end());
}
int dp[N+2][N+1][N+1]{};
vector<vi> pref(N+1,vi(N+1,0));
for (int i = 0;i<M;i++) pref[X[i]][Y[i]]+=W[i];
for (int i = 1;i<=N;i++) for (int j = 1;j<=N;j++) pref[i][j] += pref[i][j-1];
auto get = [&](int col,int l,int r) {
if (l > r) return 0ll;
return pref[col][r]-pref[col][l-1];
};
for (int i = 1ll;i<=N+1;i++) {
for (int j = 0ll;j<big(pos[i-1]);j++) {
for (int k = 0ll;k<big(pos[i]);k++) {
int h = pos[i][k];
if (i >= 2) {
for (int s = 0;s<big(pos[i-2]);s++) {
int l = pos[i-2][s];
dp[i][j][k] = max(dp[i][j][k],
dp[i-1][s][j]+get(i-1,pos[i-1][j]+1,max(l,h)));
}
}
else{
int l = 0;
dp[i][j][k] = get(i-1,pos[i-1][j]+1,max(l,h));
}
//cout << i sp j sp k sp dp[i][j][k] << '\n';
}
}
}
int ans = 0;
for (int i = 0;i<=N;i++) for (int j = 0;j<=N;j++) ans = max(ans,dp[N+1][i][j]);
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... |