This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//by szh
#include<bits/stdc++.h>
#include "fish.h"
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 3010;
ll dp[maxn][maxn][2];
int y[maxn*maxn];
int w[maxn][maxn];
int xmax,ymax;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
rep(i,0,M) {
y[i] = Y[i];
y[i]++;
w[X[i]][y[i]]=W[i];
xmax = max(X[i],xmax);
ymax = max(y[i],ymax);
}
ll ans = 0;
rep(i,0,N) rep(j,1,N+1) dp[i][j][0] = dp[i][j][1] = -1e18;
dp[0][0][0] = dp[0][N][1] = 0;
rep(i,1,N) {
//increasing
dp[i][0][0] = dp[i-1][0][0];
rep(j,1,N+1) {
dp[i][j][0] = max(dp[i-1][j][0],dp[i][j-1][0] + w[i-1][j]);
}
dp[i][N][1] = dp[i-1][N][1];
for (int j = N-1;j>=0;j--) {
dp[i][j][1] = max(dp[i-1][j][1],dp[i][j+1][1] + w[i][j+1]);
}
dp[i][0][0] = max(dp[i][0][0],dp[i-1][0][1]);
ll tmp = 0;
rep(j,1,N+1) tmp += w[i-1][j];
if (i-2>=0) dp[i][N][1] = max(dp[i][N][1],dp[i-2][N][1]+tmp);
dp[i][N][0] = dp[i][N][1] = max(dp[i][N][0],dp[i][N][1]);
rep(j,0,N+1) {
ans = max(ans,max(dp[i][j][0],dp[i][j][1]));
// cout<<i<<" "<<j<<" "<<dp[i][j][0]<<" "<<dp[i][j][1];debug(w[i][1]);
}
}
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... |