Submission #639374

# Submission time Handle Problem Language Result Execution time Memory
639374 2022-09-09T17:42:30 Z SlavicG Catfish Farm (IOI22_fish) C++17
0 / 100
984 ms 2097152 KB
#include "fish.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const ll inf = 1e16;
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    vector<vector<ll>> p(n, vector<ll>(n, 0));
    for(int i = 0; i < m; ++i) {
        p[x[i]][y[i]] += w[i];
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 1; j < n; ++j) {
            p[i][j] += p[i][j - 1];
        }
    }

    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 1, vector<ll>(2, -inf)));
    for(int i = 0; i <= n; ++i) {
        dp[0][i][0] = dp[0][i][1] = 0;
    }

    //0 - increasing, 1 - decreasing
    for(int i = 1; i < n; ++i) {
        for(int lastlen = 0; lastlen <= n; ++lastlen) {
            dp[i][0][0] = max({dp[i][0][0], dp[i - 1][lastlen][0], dp[i - 1][lastlen][1]});
            dp[i][0][1] = max({dp[i][0][1], dp[i - 1][lastlen][0], dp[i - 1][lastlen][1]});
            for(int curlen = 1; curlen <= n; ++curlen) {
                if(curlen >= lastlen) {
                    dp[i][curlen][0] = max(dp[i][curlen][0], dp[i - 1][lastlen][0] + p[i - 1][curlen - 1] - (lastlen ? p[i - 1][lastlen - 1] : 0));
                }
                if(curlen <= lastlen) {
                    dp[i][curlen][1] = max(dp[i][curlen][1], dp[i - 1][lastlen][1] + p[i][lastlen - 1] - p[i][curlen - 1]);
                    dp[i][curlen][1] = max(dp[i][curlen][1], dp[i - 1][lastlen][0] + p[i][lastlen - 1] - p[i][curlen - 1]);
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i <= n; ++i) {
        ans = max({ans, dp[n - 1][i][0], dp[n - 1][i][1]});
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 919 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 824 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 984 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 984 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 919 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -