제출 #796679

#제출 시각아이디문제언어결과실행 시간메모리
796679adrilen메기 농장 (IOI22_fish)C++17
35 / 100
108 ms10028 KiB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
using arr = array<ll, 2>;
constexpr int maxn = 305, maxm = 3e5;
int n, m;


ll fish[maxn][maxn] = { 0 };
ll dp[maxn][3][maxn] = { 0 };

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    n = N, m = M;


    for (int i = 0; i < m; i++)
    {
        fish[X[i] + 1][Y[i] + 1] += W[i];
    }

    
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= n; y++)
        {
            fish[x][y] += fish[x][y - 1];
        }
    }


    // Case 0: du er på bunnen
    // Case 1: stigende

    ll output = 0;

    for (int x = 2; x <= n + 1; x++)
    {
        for (int y = 0; y <= n; y++)
        {
            /*
            Case 0
            */

            // Case 0, 0 (y er her forrige i stedet for kommende)
            for (int y = 0; y <= n; y++)
            {
                dp[x][0][0] = max(dp[x][0][0], dp[x - 1][0][y]);
            }

            dp[x][0][y] = max(
                dp[x - 1][1][y],
                dp[x - 1][2][y]
            ) + fish[x][y]; 


            /*
            Case 1
            Stigende
            */

            for (int a = 1; a <= y; a++)
            {
                dp[x][1][y] = max(
                    dp[x][1][y], 
                    dp[x - 1][1][a] + 
                    fish[x - 1][y] - fish[x - 1][a]
                );
            }

            for (int a = 0; a <= n; a++) {
                dp[x][1][y] = max(
                    dp[x][1][y], 
                    dp[x - 1][0][a] + 
                    max(fish[x - 1][y] - fish[x - 1][a], 0ll)
                );
            }


            /*
            Case 2
            Fallende
            */

            for (int a = y + 1; a <= n; a++)
            {
                dp[x][2][y] = max(
                    dp[x][2][y],
                    max(dp[x - 1][1][a], dp[x - 1][2][a]) +
                    fish[x][a] - fish[x][y]
                );
            }

        }



    }

    // for (int x = 0; x <= n + 1; x++)
    // {   
    //     cout << "x: " << x << "\n";
    //     for (int y = 0; y < 3; y++)
    //     {
    //         for (int c = 0; c <= n; c++) cout << dp[x][y][c] << " ";
    //         cout << "\n";
    //     }
    //     cout << "\n";
    // }


    for (int i = 0; i <= n; i++) output = max(output, dp[n + 1][0][i]);

    return output;
}
#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...