Submission #633433

# Submission time Handle Problem Language Result Execution time Memory
633433 2022-08-22T13:17:24 Z Lawliet Catfish Farm (IOI22_fish) C++17
35 / 100
328 ms 224804 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][hI][hB] = 0;
            else
                dp[n][hI][hB] = s[n][hI + 1] - s[n][hB + 1];
        }
    }

    for(int i = n - 1 ; i > 0 ; 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 = dp[i + 1][0][hI];

            for(int x = n ; x >= 0 ; x--)
                maxSuffix[x] = max( maxSuffix[x + 1] , dp[i + 1][x][hI] + s[i][hI + 1] - s[i][x + 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 + s[i][hI + 1] - s[i][hB + 1] , 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 36 ms 5700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 61 ms 9668 KB Execution killed with signal 11
3 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 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 220 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 52 ms 56040 KB Output is correct
10 Correct 328 ms 221328 KB Output is correct
11 Correct 57 ms 56144 KB Output is correct
12 Correct 298 ms 221304 KB Output is correct
13 Correct 11 ms 14548 KB Output is correct
14 Correct 293 ms 221312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 220 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 52 ms 56040 KB Output is correct
10 Correct 328 ms 221328 KB Output is correct
11 Correct 57 ms 56144 KB Output is correct
12 Correct 298 ms 221304 KB Output is correct
13 Correct 11 ms 14548 KB Output is correct
14 Correct 293 ms 221312 KB Output is correct
15 Correct 320 ms 221304 KB Output is correct
16 Correct 12 ms 14528 KB Output is correct
17 Correct 316 ms 222960 KB Output is correct
18 Correct 321 ms 222912 KB Output is correct
19 Correct 301 ms 222936 KB Output is correct
20 Correct 324 ms 223016 KB Output is correct
21 Correct 303 ms 223112 KB Output is correct
22 Correct 328 ms 224804 KB Output is correct
23 Correct 292 ms 221552 KB Output is correct
24 Correct 304 ms 222380 KB Output is correct
25 Correct 287 ms 221412 KB Output is correct
26 Correct 296 ms 221484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 220 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 52 ms 56040 KB Output is correct
10 Correct 328 ms 221328 KB Output is correct
11 Correct 57 ms 56144 KB Output is correct
12 Correct 298 ms 221304 KB Output is correct
13 Correct 11 ms 14548 KB Output is correct
14 Correct 293 ms 221312 KB Output is correct
15 Correct 320 ms 221304 KB Output is correct
16 Correct 12 ms 14528 KB Output is correct
17 Correct 316 ms 222960 KB Output is correct
18 Correct 321 ms 222912 KB Output is correct
19 Correct 301 ms 222936 KB Output is correct
20 Correct 324 ms 223016 KB Output is correct
21 Correct 303 ms 223112 KB Output is correct
22 Correct 328 ms 224804 KB Output is correct
23 Correct 292 ms 221552 KB Output is correct
24 Correct 304 ms 222380 KB Output is correct
25 Correct 287 ms 221412 KB Output is correct
26 Correct 296 ms 221484 KB Output is correct
27 Runtime error 5 ms 572 KB Execution killed with signal 11
28 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 36 ms 5700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -