Submission #633431

# Submission time Handle Problem Language Result Execution time Memory
633431 2022-08-22T13:10:58 Z Lawliet Catfish Farm (IOI22_fish) C++17
0 / 100
33 ms 5812 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 310;

int n;

ll s[maxn][maxn];

ll maxSuffix[maxn];
ll dp[maxn][maxn][maxn];

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

    for(int i = 0 ; i < M ; i++)
    {
        X[i]++; Y[i]++;
        s[ X[i] ][ Y[i] ] += W[i];
    }

    for(int i = 1 ; i <= n ; i++)
        for(int j = n ; j > 0 ; j--)
            s[i][j] += s[i][j + 1];

    for(int hI = 0 ; hI <= n ; hI++)
    {
        for(int hB = 0 ; hB <= n ; hB++)
        {
            if( hB <= hI )
                dp[n - 1][hI][hB] = 0;
            else
                dp[n - 1][hI][hB] = s[n - 1][hI + 1] - s[n - 1][hB + 1];
        }
    }

    for(int i = n - 2 ; i >= 1 ; i--)
    {
        for(int hI = 0 ; hI <= n ; hI++)
        {
            // Calculating dp[i][hI][0]

            for(int x = 0 ; x <= n ; x++)
            {
                if( x <= hI )
                    dp[i][hI][0] = max( dp[i][hI][0] , dp[i + 1][x][hI] );
                else
                    dp[i][hI][0] = max( dp[i][hI][0] , dp[i + 1][x][hI] + s[i][hI + 1] - s[i][x + 1] );
            }

            // Calculating dp[i][hI][hB] (hB > 0)
            ll maxFirst = 0;

            for(int j = n ; j > 0 ; j--)
                maxSuffix[j] = max( maxSuffix[j + 1] , dp[i + 1][j][hI] + s[i][hI + 1] - s[i][j + 1] );

            for(int hB = 1 ; hB <= n ; hB++)
            {
                ll& ans = dp[i][hI][hB];

                maxFirst = max( maxFirst , dp[i + 1][hB][hI] );

                if( hB <= hI )
                {
                    ans = dp[i][hI][0];
                    continue;
                }

                ans = max( maxFirst , maxSuffix[hB + 1] );
            }
        }
    }

    ll ans = 0;

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

    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 5812 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 376 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 376 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 5812 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -