Submission #1216868

#TimeUsernameProblemLanguageResultExecution timeMemory
1216868cpdreamerCatfish Farm (IOI22_fish)C++17
52 / 100
1000 ms2162688 KiB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
typedef long long ll;
const ll MOD = (ll)1e9+7;
#define P pair
#define S second
#define F first
#define pb push_back
#define V vector
#define all(v) v.begin(), v.end()

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
    V<V<ll>>pref(N+1,V<ll>(N+1));
    for (int i=0;i<M;i++) {
        pref[X[i]][Y[i]+1]+=W[i];
    }
    for (int i=0;i<=N;i++) {
        for (int j=1;j<=N;j++) {
            pref[i][j]+=pref[i][j-1];
        }
    }
    ll dp[N][N+1][2];
    ll maxp[N][N+2][2];
    ll maxs[N][N+2][2];
    memset(dp,0,sizeof(dp));
    memset(maxp,0,sizeof(maxp));
    memset(maxs,0,sizeof(maxs));
    ll maxd=0;
    for (int j=0;j<=N;j++) {
        maxd=max(maxd,dp[0][j][0]);
    }
    for (int j=N;j>=0;j--) {
        maxs[0][j][0]=max(maxs[0][j+1][0],max(dp[0][j][0],dp[0][j][1])+pref[0+1][j]);
        maxs[0][j][1]=max(maxs[0][j+1][1],dp[0][j][1]);
    }
    maxp[0][0][1]=max(dp[0][0][1],dp[0][0][0]);
    maxp[0][0][0]=dp[0][0][1]-pref[0][0];
    for (int j=1;j<=N;j++) {
        maxp[0][j][1]=max(maxp[0][j-1][1],max(dp[0][j][0],dp[0][j][1]));
        maxp[0][j][0]=max(maxp[0][j-1][0],dp[0][j][1]-pref[0][j]);
    }

    for (int i=1;i<N;i++) {
        for (int j=0;j<=N;j++) {
            dp[i][j][0]=max(dp[i][j][0],max(maxs[i-1][j][0]-pref[i][j],maxp[i-1][j][1]));
            dp[i][j][1]=max(dp[i][j][1],max(maxd,max(maxp[i-1][j][0]+pref[i-1][j],maxs[i-1][j][1])));
        }
        for (int j=0;j<=N;j++) {
            maxd=max(maxd,dp[i][j][0]);
        }
        for (int j=N;j>=0;j--) {
            maxs[i][j][0]=max(maxs[i][j+1][0],max(dp[i][j][0],dp[i][j][1])+pref[i+1][j]);
            maxs[i][j][1]=max(maxs[i][j+1][1],dp[i][j][1]);
        }
        maxp[i][0][1]=max(dp[i][0][1],dp[i][0][0]);
        maxp[i][0][0]=dp[i][0][1]-pref[i][0];
        for (int j=1;j<=N;j++) {
            maxp[i][j][1]=max(maxp[i][j-1][1],max(dp[i][j][0],dp[i][j][1]));
            maxp[i][j][0]=max(maxp[i][j-1][0],dp[i][j][1]-pref[i][j]);
        }
    }
    ll ans=0;
    for (int i=0;i<=N;i++) {
        ans=max(ans,max(dp[N-1][i][0],dp[N-1][i][1]));
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...