#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> ti;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define LSOne(s) ((s)&(-s))
#define all(x) (x).begin(),(x).end()
ll INF=9000000000000000010;
int inf=1e9+10;
ll M=1e9+7;
long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
vector<vector<ll>> dp(n,vector<ll>(n+1,0)),a(n,vector<ll>(n+1,0)),b(n,vector<ll>(n+1,0)),c(n,vector<ll>(n+1,0)),d(n,vector<ll>(n+1,0)),e(n,vector<ll>(n+1,0));
REP(i,0,m)a[X[i]][Y[i]+1]=(ll)W[i];
REP(i,0,n)REP(j,1,n+1)a[i][j]+=a[i][j-1];
dp[0]=a[1];
dp[1]=a[0];
if(n>2)REP(j,0,n+1)dp[1][j]+=a[2][j];
b[0]=dp[0];c[0]=dp[0];
b[1]=dp[1];c[1]=dp[1];d[1]=a[0];e[1]=a[0];
REP(j,1,n+1)e[1][j]-=a[1][j];
REP(j,2,n+1)e[1][j]=max(e[1][j],e[1][j-1]);
REP(i,0,2)REP(j,2,n+1)b[i][j]=max(b[i][j],b[i][j-1]);
REP(i,0,2)REP(j,2,n+1)d[i][j]=max(d[i][j],d[i][j-1]);
REP(i,0,2)for(int j=n-1;j>=1;j--)c[i][j]=max(c[i][j],c[i][j+1]);
REP(i,2,n){
dp[i][0]=max(b[i-1].back(),b[i-2].back());
REP(j,1,n+1){
dp[i][j]=a[i-1][j]+(i+1<n?a[i+1][j]:0LL)+dp[i-2][0];
dp[i][j]=max(dp[i][j],a[i-1][j]+(i+1<n?a[i+1][j]:0LL)+d[i-2][j]);
dp[i][j]=max(dp[i][j],e[i-1][j]+a[i-1][j]+(i+1<n?a[i+1][j]:0LL));
}
e[i]=dp[i];
REP(j,1,n+1)e[i][j]-=a[i][j]+(i+1<n?a[i+1][j]:0);
REP(j,2,n+1)e[i][j]=max(e[i][j],e[i][j-1]);
REP(j,1,n){
dp[i][j]=max(dp[i][j],c[i-2][j+1]+(i+1<n?a[i+1][j]:0LL));
dp[i][j]=max(dp[i][j],c[i-1][j+1]-a[i][j]+(i+1<n?a[i+1][j]:0LL));
}
b[i]=dp[i];c[i]=dp[i];d[i]=dp[i];
REP(j,1,n+1)d[i][j]-=(i+1<n?a[i+1][j]:0LL);
REP(j,2,n+1)b[i][j]=max(b[i][j],b[i][j-1]);
REP(j,2,n+1)d[i][j]=max(d[i][j],d[i][j-1]);
for(int j=n-1;j>=1;j--)c[i][j]=max(c[i][j],c[i][j+1]);
}
ll ans=0;
REP(i,0,n)ans=max(ans,*max_element(all(dp[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... |