Submission #634116

# Submission time Handle Problem Language Result Execution time Memory
634116 2022-08-23T20:24:44 Z Utaha Catfish Farm (IOI22_fish) C++17
0 / 100
1000 ms 2097152 KB
#include "fish.h"

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

const int maxN = 100005;

int n_col = 0;
long long dp[10][3][maxN];
vector<vector<long long>> grid;
vector<vector<long long>> prefix;
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) {
    for(auto i : X) {
        n_col = max(n_col, i + 4);
    }

    for(int i = 0; i < N + 2; i++) {
        grid.push_back(vector<long long>(N, 0));      
        prefix.push_back(vector<long long>(N + 1, 0));
    }

    for(int i = 0; i < M; i++) {
        grid[X[i] + 1][Y[i]] = W[i];
    }
    for(int i = 0; i < n_col; i++) {
        prefix[i][0] = 0;
        for(int j = 0; j < int(grid[i].size()); j++) {
            prefix[i][j + 1] = prefix[i][j] + grid[i][j];
        }
    }



    for(int i = 0; i < n_col; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k <= N; 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] = prefix[0][k];
                    }
                }
                if (i == n_col - 1) break;

                if (j == UP) {
                    for(int t = k; t <= N; 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]);
                    }
                }
                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
                    for(int t = 0; t <= N; 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 Execution timed out 1132 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 787 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 754 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Runtime error 1 ms 340 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Runtime error 1 ms 340 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Runtime error 1 ms 340 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 754 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1132 ms 2097152 KB Time limit exceeded
2 Halted 0 ms 0 KB -