Submission #729761

# Submission time Handle Problem Language Result Execution time Memory
729761 2023-04-24T14:14:26 Z Nahian9696 Catfish Farm (IOI22_fish) C++17
32 / 100
87 ms 21856 KB
#include "fish.h"

#include <vector>
#include <bits/stdc++.h>

using namespace std;


#define f0(i, n) for(int i = 0; i <  (n); i++)
#define f1(i, n) for(int i = 1; i <= (n); i++)
#define pb push_back
#define ff first
#define ss second

typedef vector<int> vi;
typedef long long ll;



long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    bool allxeven = true;
    bool allxleq1 = true;
    bool ally0 = true;

    f0(i, M) {
        if(X[i] % 2 == 1) allxeven = false;
        if(X[i] > 1) allxleq1 = false;
        if(Y[i] != 0) ally0 = false;
    }


    if (allxeven) {
        ll ret = 0;
        f0(i, M) ret += W[i];
        return ret;
    } 
    if(allxleq1) {
        ll ret = 0;
        ll ans = 0;
        int arr[N][2];
        f0(i, N) arr[i][0] = 0, arr[i][1] = 0;
        f0(i, M) {
            arr[Y[i]][X[i]] = W[i];
        }

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

        f0(i, N) {
            ans += arr[i][1];
        }
        ret = ans;
        f0(i, N) {
            ans -= arr[i][1];
            ans += arr[i][0];
            ret = max(ret, ans);
        }
        return ret;
    }
    if(ally0) {
        int arr[N];
        f0(i, N) arr[i] = 0;
        f0(i, M) arr[X[i]] = W[i];
        ll dp[N][4];
        dp[0][0] = -1e18;
        dp[0][1] = -1e18;
        dp[0][2] = 0;
        dp[0][3] = arr[0];

        dp[1][0] = 0;
        dp[1][1] = arr[1];
        dp[1][2] = arr[0];
        dp[1][3] = -1e18;


        f1(i, N-2) {
            dp[i+1][0] = max(dp[i][0], dp[i][2]);
            dp[i+1][1] = max(dp[i][0], dp[i][2]) + arr[i+1];
            dp[i+1][2] = max(dp[i][1], dp[i][3]);
            dp[i+1][3] = dp[i][1] + arr[i+1];
        }
        return max({
            dp[N-1][0],
            dp[N-1][1],
            dp[N-1][2]
        });
    }


    ll arr[N][10];
    f0(i, N) f0(j, 10) arr[i][j] = 0;


    f0(i, M) {
        arr[X[i]][Y[i]+1] = W[i];
    }

    ll prefarr[N][10];
    f0(i, N) prefarr[i][0] = 0;

    f0(i, N) f1(j, 9) {
        prefarr[i][j] = prefarr[i][j-1] + arr[i][j];
    }

    ll dp[N][10][10][10];
    ll mxdp[N][10][10];

    f0(i, 10) f0(j, 10) {
        f0(k, 10) dp[0][i][j][k] = 0;
        mxdp[0][i][j] = 0;
    }


    f0(i, 10) f0(j, 10) {
        ll val = 0;
        if(i > j) {
            for(int x = j+1; x <= i; x++) val += arr[0][x];
        } else {
            for(int x = i+1; x <= j; x++) val += arr[1][x];
        }
        mxdp[1][i][j] = val;
        f0(k, 10) {
            dp[1][i][j][k] = val;
        }
    }


    f1(col, N-2) {
        f0(i, 10) f0(j, 10) {
            ll mx = 0;
            f0(k, 10) {
                dp[col+1][i][j][k] = mxdp[col][j][k];
                if(max(j, k) <= i) {
                    dp[col+1][i][j][k] += prefarr[col][i] - prefarr[col][max(j, k)];
                }
                if(j >= i) dp[col+1][i][j][k] += prefarr[col+1][j] - prefarr[col+1][i];
                mx = max(mx, dp[col+1][i][j][k]);
            }
            mxdp[col+1][i][j] = mx;
            // cout << mx << endl;
        }
    }

    ll ans = 0;
    f0(i, 10) f0(j, 10) ans = max(ans, mxdp[N-1][i][j]);

    return ans;

    return 9;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3020 KB Output is correct
2 Correct 31 ms 3532 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 87 ms 8196 KB Output is correct
6 Correct 86 ms 8164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 47 ms 5648 KB Output is correct
3 Correct 57 ms 9156 KB Output is correct
4 Correct 23 ms 3540 KB Output is correct
5 Correct 28 ms 4284 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 24 ms 4204 KB Output is correct
13 Correct 27 ms 5072 KB Output is correct
14 Correct 24 ms 4196 KB Output is correct
15 Correct 28 ms 4684 KB Output is correct
16 Correct 24 ms 4316 KB Output is correct
17 Correct 27 ms 4668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 3796 KB Output is correct
3 Correct 17 ms 5640 KB Output is correct
4 Correct 12 ms 5200 KB Output is correct
5 Correct 31 ms 7104 KB Output is correct
6 Correct 25 ms 7052 KB Output is correct
7 Correct 28 ms 6976 KB Output is correct
8 Correct 30 ms 6988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 1620 KB Output is correct
10 Correct 3 ms 2900 KB Output is correct
11 Correct 1 ms 1620 KB Output is correct
12 Correct 3 ms 2872 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 3 ms 2852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 1620 KB Output is correct
10 Correct 3 ms 2900 KB Output is correct
11 Correct 1 ms 1620 KB Output is correct
12 Correct 3 ms 2872 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 3 ms 2852 KB Output is correct
15 Runtime error 5 ms 5716 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 1620 KB Output is correct
10 Correct 3 ms 2900 KB Output is correct
11 Correct 1 ms 1620 KB Output is correct
12 Correct 3 ms 2872 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 3 ms 2852 KB Output is correct
15 Runtime error 5 ms 5716 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 3796 KB Output is correct
3 Correct 17 ms 5640 KB Output is correct
4 Correct 12 ms 5200 KB Output is correct
5 Correct 31 ms 7104 KB Output is correct
6 Correct 25 ms 7052 KB Output is correct
7 Correct 28 ms 6976 KB Output is correct
8 Correct 30 ms 6988 KB Output is correct
9 Runtime error 41 ms 21856 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3020 KB Output is correct
2 Correct 31 ms 3532 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 87 ms 8196 KB Output is correct
6 Correct 86 ms 8164 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 47 ms 5648 KB Output is correct
9 Correct 57 ms 9156 KB Output is correct
10 Correct 23 ms 3540 KB Output is correct
11 Correct 28 ms 4284 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 24 ms 4204 KB Output is correct
19 Correct 27 ms 5072 KB Output is correct
20 Correct 24 ms 4196 KB Output is correct
21 Correct 28 ms 4684 KB Output is correct
22 Correct 24 ms 4316 KB Output is correct
23 Correct 27 ms 4668 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 3796 KB Output is correct
26 Correct 17 ms 5640 KB Output is correct
27 Correct 12 ms 5200 KB Output is correct
28 Correct 31 ms 7104 KB Output is correct
29 Correct 25 ms 7052 KB Output is correct
30 Correct 28 ms 6976 KB Output is correct
31 Correct 30 ms 6988 KB Output is correct
32 Correct 1 ms 296 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 2 ms 1620 KB Output is correct
41 Correct 3 ms 2900 KB Output is correct
42 Correct 1 ms 1620 KB Output is correct
43 Correct 3 ms 2872 KB Output is correct
44 Correct 1 ms 852 KB Output is correct
45 Correct 3 ms 2852 KB Output is correct
46 Runtime error 5 ms 5716 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -