Submission #729855

# Submission time Handle Problem Language Result Execution time Memory
729855 2023-04-24T18:13:56 Z caganyanmaz Catfish Farm (IOI22_fish) C++17
0 / 100
53 ms 11040 KB
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
using namespace std;

constexpr static int SIZE = 301;
int dp[SIZE][SIZE][2];
int grid[SIZE][SIZE];


int max_weights_special(int32_t n, int32_t m, vector<int32_t> x, vector<int32_t> y, vector<int32_t> w)
{
        array<int, 2> res;
        for (int i = 0; i < m; i++)
                res[x[i]] += w[i];
        return max(res[0], res[1]);
}
int max_weights(int32_t n, int32_t m, vector<int32_t> x, vector<int32_t> y, vector<int32_t> w)
{
        if (n == 2)
                return max_weights_special(n, m, x, y, w);
        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] = 0;
        for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                        grid[i][j] = 0;

        for (int i = 0; i < m; i++)
                grid[x[i]][y[i]] = w[i];
        for (int i = 1; i <= n; i++)
        {
                dp[1][i][0] = dp[1][i-1][0] + grid[0][i-1];
                dp[1][i][1] = dp[1][i][0];
        }
        for (int i = 2; i < n; i++)
        {
                vector<int> b_l(n+1), b_h(n+1);
                vector<int> prefix(n+1);
                for (int j = 1; j <= n; j++)
                        prefix[j] = prefix[j-1] + grid[i-1][j-1];
                for (int j = 1; j <= n; j++)
                        b_l[j] = max({b_l[j-1], dp[i-2][j-1][0], dp[i-2][j-1][1]});
                b_h[n] = max(dp[i-2][n][0], dp[i-2][n][1]) + prefix[n];
                for (int j = n-1; j >= 0; j--)
                        b_h[j] = max(b_h[j+1], max(dp[i-2][j][0], dp[i-2][j][1]) + prefix[j]);
                for (int j = 1; j <= n; j++)
                        dp[i][j][0] = grid[i-1][j-1] + max({dp[i][j-1][0], dp[i-1][j-1][0]});
                for (int j = n-1; j >= 0; j--)
                        dp[i][j][1] = max({dp[i][j+1][1], dp[i-1][j+1][1], dp[i-1][j+1][0]}) + grid[i][j];
                for (int j = 0; j <= n; j++)
                {
                        dp[i][j][0] = max({dp[i][j][0], b_l[j] + prefix[j], b_h[j]});
                        dp[i][j][1] = max({dp[i][j][1], b_l[j] + prefix[j], b_h[j]});
                }
        }
        vector<int> prefix(n+1);
        for (int i = 1; i <= n; i++)
                prefix[i] = prefix[i-1] + grid[n-1][i-1];
        int best = 0;
        for (int i = 0; i <= n; i++)
                best = max(best, dp[n-1][i][0]);
        for (int i = 0; i <= n; i++)
                best = max(best, max(dp[n-2][i][1], dp[n-2][i][0]) + prefix[i]);
        return best;
}
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 7040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 53 ms 11040 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 3192 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '140726926999334'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '140726926999334'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '4044', found: '140726926999334'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 3192 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 7040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -