Submission #627283

# Submission time Handle Problem Language Result Execution time Memory
627283 2022-08-12T11:48:44 Z typ_ik Catfish Farm (IOI22_fish) C++17
18 / 100
84 ms 7280 KB
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()

using namespace std;

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    int block1 = 0;
    for (auto c : X) block1 += (c & 1 ^ 1);
    if (block1 == M)
        return accumulate(all(W), 0ll);

    int mx = -1;
    for (auto c : X) mx = max(mx, c);

    if (mx <= 1) {
        vector <long long> col[2];
        for (auto i : {0, 1})
            col[i].resize(N);

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

        for (int i = 0; i < 2; i++)
            for (int j = 1; j < N; j++)
                col[i][j] += col[i][j-1];

        if (N == 2)
            return max({col[1][N-1], col[0][1], col[0][0]});

        long long ans = col[1][N - 1];
        for (int i = 0; i < N; i++)
            ans = max(ans, col[0][i] + (col[1][N - 1] - col[1][i]));

        return ans;
    }

    long long dp[N + 1][2];
    long long val[N + 1];
    for (int i = 0; i <= N; i++) {
        for (int j : {0, 1})
            dp[i][j] = 0;
        val[i] = 0;
    }

    for (int i = 0; i < M; i++)
        X[i]++;
    for (int i = 0; i < M; i++)
        val[X[i]] = W[i];

    dp[0][1] = val[1];

    for (int i = 2; i <= N; i++) {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = max(dp[i - 1][1] - val[i], max(dp[i - 2][0] + val[i - 1], dp[i - 2][1])) + val[i + 1];
    }

    return max(dp[N - 1][0], dp[N - 1][1]);
}

//main() {
//    int N = 10, M = 4;
//    vector <int> X = {0, 5, 7, 4};
//    vector <int> Y = {0, 0, 0, 0};
//    vector <int> W = {10, 5, 3, 6};
//    cout << max_weights(N, M, X, Y, W) << '\n';
//}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:9:35: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    9 |     for (auto c : X) block1 += (c & 1 ^ 1);
      |                                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2148 KB Output is correct
2 Correct 25 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 81 ms 7280 KB Output is correct
6 Correct 84 ms 7264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 44 ms 5412 KB Output is correct
3 Correct 59 ms 6480 KB Output is correct
4 Correct 21 ms 2152 KB Output is correct
5 Correct 26 ms 2636 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 24 ms 4956 KB Output is correct
13 Correct 32 ms 5940 KB Output is correct
14 Correct 24 ms 4940 KB Output is correct
15 Correct 28 ms 5576 KB Output is correct
16 Correct 25 ms 4964 KB Output is correct
17 Correct 27 ms 5432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 2516 KB Output is correct
3 Correct 15 ms 3636 KB Output is correct
4 Correct 11 ms 3484 KB Output is correct
5 Correct 27 ms 4920 KB Output is correct
6 Correct 23 ms 4948 KB Output is correct
7 Correct 26 ms 4948 KB Output is correct
8 Correct 26 ms 4932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 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 212 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 212 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 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 2516 KB Output is correct
3 Correct 15 ms 3636 KB Output is correct
4 Correct 11 ms 3484 KB Output is correct
5 Correct 27 ms 4920 KB Output is correct
6 Correct 23 ms 4948 KB Output is correct
7 Correct 26 ms 4948 KB Output is correct
8 Correct 26 ms 4932 KB Output is correct
9 Incorrect 33 ms 4948 KB 1st lines differ - on the 1st token, expected: '99999', found: '66666'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2148 KB Output is correct
2 Correct 25 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 81 ms 7280 KB Output is correct
6 Correct 84 ms 7264 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 44 ms 5412 KB Output is correct
9 Correct 59 ms 6480 KB Output is correct
10 Correct 21 ms 2152 KB Output is correct
11 Correct 26 ms 2636 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 24 ms 4956 KB Output is correct
19 Correct 32 ms 5940 KB Output is correct
20 Correct 24 ms 4940 KB Output is correct
21 Correct 28 ms 5576 KB Output is correct
22 Correct 25 ms 4964 KB Output is correct
23 Correct 27 ms 5432 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 2516 KB Output is correct
26 Correct 15 ms 3636 KB Output is correct
27 Correct 11 ms 3484 KB Output is correct
28 Correct 27 ms 4920 KB Output is correct
29 Correct 23 ms 4948 KB Output is correct
30 Correct 26 ms 4948 KB Output is correct
31 Correct 26 ms 4932 KB Output is correct
32 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
33 Halted 0 ms 0 KB -