Submission #1234725

#TimeUsernameProblemLanguageResultExecution timeMemory
1234725Sir_Ahmed_ImranCatfish Farm (IOI22_fish)C++17
0 / 100
672 ms74868 KiB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define MAXN 3001
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define ld long double
#define terminator main
#define pll pair<ll,ll>
#define add insert
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()

ll z[MAXN][2];
ll a[MAXN][MAXN];
ll dp[MAXN][MAXN][2];

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){
    for(int i = 0; i < m; i++)
        a[x[i]][y[i]] = w[i];
    for(int i = 0; i < n; i++)
        for(int j = 1; j < n; j++)
            a[i][j] += a[i][j - 1];
    for(int i = 0; i <= n; i++)
        for(int j = 0; j < n; j++)
            for(int k = 0; k < 2; k++)
                dp[i][j][k] = z[i][k] = -1e18;
    z[0][0] = z[0][1] = 0;
    for(int j = 0; j < n; j++){
        dp[0][j][0] = 0;
        dp[0][j][1] = a[1][n - 1];
    }
    z[1][1] = 0;
    z[1][0] = a[1][n - 1];
    ll ans = 0;
    for(int i = 1; i < n; i++){
        z[i][1] = max(z[i][1], z[i - 1][0]);
        for(int j = 0; j < n; j++){
            dp[i][j][0] = max(dp[i][j][0], z[i - 1][0] - a[i][j]);
            dp[i][j][0] = max(dp[i][j][0], z[i - 1][1] + a[i - 1][j] - a[i][j]);
            dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][0] + a[i - 1][j] - a[i][j]);
            dp[i][j][1] = max(dp[i][j][1], z[i - 1][0] + a[i + 1][j]);
            dp[i][j][1] = max(dp[i][j][1], z[i - 1][1] + a[i - 1][j] + a[i + 1][j]);
            dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][1] - a[i][j] + a[i + 1][j]);
            dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][0] + a[i - 1][j] + a[i + 1][j]);
            z[i + 1][0] = max(z[i][0], dp[i][j][1]);
            z[i + 1][1] = max(z[i][1], max(dp[i][j][1] - a[i + 1][j], dp[i][j][0] + a[i][j]));
            ans = max(ans, max(dp[i][j][1] - a[i + 1][j], dp[i][j][0] + a[i][j]));
        }
        for(int j = 1; j < n; j++)
            dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][0]);
        for(int j = n - 2; j >= 0; j--)
            dp[i][j][1] = max(dp[i][j][1], dp[i][j + 1][1]);
        z[i + 1][0] = max(z[i + 1][0], z[i][0]);
        z[i + 1][1] = max(z[i + 1][1], z[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...