Submission #634141

# Submission time Handle Problem Language Result Execution time Memory
634141 2022-08-23T21:48:57 Z Utaha Catfish Farm (IOI22_fish) C++17
35 / 100
138 ms 13996 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;

const int maxN = 305;

int n_col = 0;
const int max_height = maxN;
long long dp[maxN][3][max_height + 1];
long long prefix[maxN][max_height + 1];
const long long INF = 1e18;
const int UP = 0;
const int DOWN = 1;
const int STOP = 2;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    n_col = N + 2;

    for(int i = 0; i < M; i++) {
        prefix[X[i] + 1][Y[i] + 1] = W[i];
    }
    for(int i = 0; i < n_col; i++) {
        for(int j = 0; j < N; j++) {
            prefix[i][j + 1] += prefix[i][j];
        }
    }
    // for(int i = 0; i < n_col; i++) {
    //     for(int j = 0; j < prefix[i].size(); j++) {
    //         cout << prefix[i][j] << ' ';
    //     }
    //     cout<<'\n';
    // }

    for(int i = 0; i < n_col; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k <= max_height; k++) {
                // printf("%d %d %d %lld\n", i, j, k, dp[i][j][k]);
                if (i == 0) {
                    if (j != UP) {
                        dp[i][j][k] = -INF;
                    }
                    else {
                        dp[i][j][k] = 0;
                    }
                }
                if (i == n_col - 1) break;

                if (j == UP) {
                    for(int t = k; t <= max_height; t++) {
                        dp[i + 1][UP][t] = max(dp[i + 1][UP][t], dp[i][j][k] + prefix[i + 1][t] - prefix[i + 1][k]);
                        // printf("DEBUG: %d %d %lld\n",i, t, dp[i + 1][UP][t]);
                    }
                    dp[i + 1][STOP][k] = max(dp[i + 1][STOP][k], dp[i][j][k]);
                }
                else if(j == STOP) {
                    for(int t = 0; t <= k; t++){
                        dp[i + 1][DOWN][t] = max(dp[i + 1][DOWN][t], dp[i][j][k] + prefix[i + 1][k] - prefix[i + 1][t]);
                    }
                    // down and immediately up
                    // maybe this case doesn't even exist...
                    for(int t = 0; t <= max_height; t++) {
                        const int height = max(t, k);

                        // printf("check: %d %d %lld % lld\n",i, t, dp[i][j][k], prefix[i + 1][height]);
                        dp[i + 1][UP][t] = max(dp[i + 1][UP][t], dp[i][j][k] + prefix[i + 1][height]);
                        // printf("DEBU2: %d %d %lld\n",i, t, dp[i + 1][UP][t]);
                    }
                }
                else{
                    for(int t = 0; t <= k; t++) {
                        dp[i + 1][DOWN][t] = max(dp[i + 1][DOWN][t], dp[i][j][k] + prefix[i + 1][k] - prefix[i + 1][t]);
                    }
                    // down and immediately up
                    // maybe this case doesn't even exist...
                    for(int t = 0; t <= max_height; t++) {
                        const int height = max(t, k);

                        // printf("check: %d %d %lld % lld\n",i, t, dp[i][j][k], prefix[i + 1][height]);
                        dp[i + 1][UP][t] = max(dp[i + 1][UP][t], dp[i][j][k] + prefix[i + 1][height]);
                        // printf("DEBU2: %d %d %lld\n",i, t, dp[i + 1][UP][t]);
                    }
                }
            }
        }
    }
    return dp[n_col - 1][DOWN][0];
}
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 10176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Runtime error 114 ms 13996 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 78 ms 6200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 59 ms 1744 KB Output is correct
10 Correct 116 ms 3160 KB Output is correct
11 Correct 59 ms 1740 KB Output is correct
12 Correct 136 ms 3204 KB Output is correct
13 Correct 31 ms 948 KB Output is correct
14 Correct 120 ms 3124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 59 ms 1744 KB Output is correct
10 Correct 116 ms 3160 KB Output is correct
11 Correct 59 ms 1740 KB Output is correct
12 Correct 136 ms 3204 KB Output is correct
13 Correct 31 ms 948 KB Output is correct
14 Correct 120 ms 3124 KB Output is correct
15 Correct 119 ms 3092 KB Output is correct
16 Correct 30 ms 1048 KB Output is correct
17 Correct 134 ms 4908 KB Output is correct
18 Correct 129 ms 4812 KB Output is correct
19 Correct 128 ms 4752 KB Output is correct
20 Correct 130 ms 4844 KB Output is correct
21 Correct 132 ms 4852 KB Output is correct
22 Correct 138 ms 6612 KB Output is correct
23 Correct 125 ms 3368 KB Output is correct
24 Correct 129 ms 4240 KB Output is correct
25 Correct 120 ms 3276 KB Output is correct
26 Correct 123 ms 3320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 59 ms 1744 KB Output is correct
10 Correct 116 ms 3160 KB Output is correct
11 Correct 59 ms 1740 KB Output is correct
12 Correct 136 ms 3204 KB Output is correct
13 Correct 31 ms 948 KB Output is correct
14 Correct 120 ms 3124 KB Output is correct
15 Correct 119 ms 3092 KB Output is correct
16 Correct 30 ms 1048 KB Output is correct
17 Correct 134 ms 4908 KB Output is correct
18 Correct 129 ms 4812 KB Output is correct
19 Correct 128 ms 4752 KB Output is correct
20 Correct 130 ms 4844 KB Output is correct
21 Correct 132 ms 4852 KB Output is correct
22 Correct 138 ms 6612 KB Output is correct
23 Correct 125 ms 3368 KB Output is correct
24 Correct 129 ms 4240 KB Output is correct
25 Correct 120 ms 3276 KB Output is correct
26 Correct 123 ms 3320 KB Output is correct
27 Runtime error 1 ms 596 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 78 ms 6200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 10176 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -