Submission #858778

# Submission time Handle Problem Language Result Execution time Memory
858778 2023-10-09T07:40:33 Z LucaIlie Catfish Farm (IOI22_fish) C++17
14 / 100
1000 ms 380736 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 3e5 + 2;
const long long INF = 1e18;
map<int, long long> costCell[MAX_N], dp[MAX_N], dpLower[MAX_N], spX[MAX_N];
vector <int> ys[MAX_N];

long long max_weights( int n, int m, vector <int> X, vector <int> Y, vector <int> W ) {

    for ( int i = 0; i < m; i++ ) {
        X[i]++;
        Y[i]++;
        costCell[X[i]][Y[i]] = W[i];
        ys[X[i] - 1].push_back( Y[i] );
        ys[X[i] + 1].push_back( Y[i] );
        ys[X[i]].push_back( Y[i] );
    }

    ys[0].clear();
    ys[n + 1].clear();
    for ( int x = 0; x <= n + 1; x++ )
        ys[x].push_back( 0 );
    for ( int x = 1; x <= n; x++ ) {
        sort( ys[x].begin(), ys[x].end() );
        ys[x].resize( unique( ys[x].begin(), ys[x].end() ) - ys[x].begin() );
    }

    for ( int x = 1; x <= n; x++ ) {
        for ( int y = 1; y <= n; y++ )
            spX[x][y] = spX[x][y - 1] + costCell[x][y];
    }

    dp[0][0] = dpLower[0][0] = 0;
    for ( int x = 1; x <= n + 1; x++ ) {
        for ( int i = 0; i < ys[x].size(); i++ ) {
            int crtY = ys[x][i];

            dp[x][crtY] = dpLower[x][crtY] = -INF;
            for ( int j = 0; j < ys[x - 1].size(); j++ ) {
                int prevY = ys[x - 1][j];

                if ( prevY <= crtY ) {
                    dpLower[x][crtY] = max( dpLower[x][crtY], dpLower[x - 1][prevY] + spX[x - 1][crtY] - spX[x - 1][prevY] );
                    dp[x][crtY] = max( dp[x][crtY], dpLower[x - 1][prevY] + spX[x - 1][crtY] - spX[x - 1][prevY] );
                }
                if ( prevY >= crtY )
                    dp[x][crtY] = max( dp[x][crtY], dp[x - 1][prevY] + spX[x][prevY] - spX[x][crtY] );
            }

            if ( x == 1 )
                continue;
            for ( int j = 0; j < ys[x - 2].size(); j++ ) {
                int prevY = ys[x - 2][j];

                if ( prevY <= crtY ) {
                    dpLower[x][crtY] = max( dpLower[x][crtY], dp[x - 2][prevY] + spX[x - 1][crtY] );
                    dp[x][crtY] = max( dp[x][crtY], dp[x - 2][prevY] + spX[x - 1][crtY] );
                }
                if ( prevY >= crtY ) {
                    dpLower[x][crtY] = max( dpLower[x][crtY], dp[x - 2][prevY] + spX[x - 1][prevY] );
                    dp[x][crtY] = max( dp[x][crtY], dp[x - 2][prevY] + spX[x - 1][prevY] );
                }
            }
        }
    }

    return dp[n + 1][0];
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:38:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for ( int i = 0; i < ys[x].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~~
fish.cpp:42:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for ( int j = 0; j < ys[x - 1].size(); j++ ) {
      |                              ~~^~~~~~~~~~~~~~~~~~
fish.cpp:55:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for ( int j = 0; j < ys[x - 2].size(); j++ ) {
      |                              ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1117 ms 379148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 63836 KB Output is correct
2 Execution timed out 1070 ms 361960 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1116 ms 380736 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 63832 KB Output is correct
2 Correct 14 ms 64032 KB Output is correct
3 Correct 13 ms 63836 KB Output is correct
4 Correct 12 ms 63616 KB Output is correct
5 Correct 13 ms 63680 KB Output is correct
6 Correct 12 ms 63836 KB Output is correct
7 Correct 12 ms 63836 KB Output is correct
8 Correct 13 ms 63844 KB Output is correct
9 Correct 20 ms 66664 KB Output is correct
10 Correct 41 ms 75576 KB Output is correct
11 Correct 20 ms 66652 KB Output is correct
12 Correct 40 ms 75344 KB Output is correct
13 Correct 14 ms 64604 KB Output is correct
14 Correct 36 ms 75348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 63832 KB Output is correct
2 Correct 14 ms 64032 KB Output is correct
3 Correct 13 ms 63836 KB Output is correct
4 Correct 12 ms 63616 KB Output is correct
5 Correct 13 ms 63680 KB Output is correct
6 Correct 12 ms 63836 KB Output is correct
7 Correct 12 ms 63836 KB Output is correct
8 Correct 13 ms 63844 KB Output is correct
9 Correct 20 ms 66664 KB Output is correct
10 Correct 41 ms 75576 KB Output is correct
11 Correct 20 ms 66652 KB Output is correct
12 Correct 40 ms 75344 KB Output is correct
13 Correct 14 ms 64604 KB Output is correct
14 Correct 36 ms 75348 KB Output is correct
15 Correct 36 ms 75088 KB Output is correct
16 Correct 57 ms 64960 KB Output is correct
17 Execution timed out 1035 ms 79472 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 63832 KB Output is correct
2 Correct 14 ms 64032 KB Output is correct
3 Correct 13 ms 63836 KB Output is correct
4 Correct 12 ms 63616 KB Output is correct
5 Correct 13 ms 63680 KB Output is correct
6 Correct 12 ms 63836 KB Output is correct
7 Correct 12 ms 63836 KB Output is correct
8 Correct 13 ms 63844 KB Output is correct
9 Correct 20 ms 66664 KB Output is correct
10 Correct 41 ms 75576 KB Output is correct
11 Correct 20 ms 66652 KB Output is correct
12 Correct 40 ms 75344 KB Output is correct
13 Correct 14 ms 64604 KB Output is correct
14 Correct 36 ms 75348 KB Output is correct
15 Correct 36 ms 75088 KB Output is correct
16 Correct 57 ms 64960 KB Output is correct
17 Execution timed out 1035 ms 79472 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1116 ms 380736 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1117 ms 379148 KB Time limit exceeded
2 Halted 0 ms 0 KB -