Submission #858795

# Submission time Handle Problem Language Result Execution time Memory
858795 2023-10-09T08:00:39 Z LucaIlie Catfish Farm (IOI22_fish) C++17
0 / 100
1000 ms 1026460 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 3e5 + 2;
const long long INF = 1e18;
unordered_map<int, long long> costCell[MAX_N], dp[MAX_N], dpLower[MAX_N], spX[MAX_N], max1[MAX_N], max2[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 prevY: ys[x - 1] ) {
                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] );
            }*/
            auto lower = upper_bound( ys[x - 1].begin(), ys[x - 1].end(), crtY );
            auto upper = lower_bound( ys[x - 1].begin(), ys[x - 1].end(), crtY );

            if ( lower != ys[x - 1].begin() ) {
                lower--;
                int prevY = *lower;
                dpLower[x][crtY] = max( dpLower[x][crtY], max1[x - 1][prevY] + spX[x - 1][crtY] );
                dp[x][crtY] = max( dp[x][crtY], max1[x - 1][prevY] + spX[x - 1][crtY] );
            }
            if ( upper != ys[x - 1].end() ) {
                int prevY = *lower;
                dp[x][crtY] = max( dp[x][crtY], max2[x - 1][prevY] - spX[x][crtY] );
            }

            if ( x == 1 )
                continue;
            for ( int prevY: ys[x - 2] ) {
                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] );
                }
            }

            max1[x][crtY] = max( (i > 0 ? max1[x][ys[x][i - 1]] : -INF), dpLower[x][crtY] - spX[x][crtY] );
            max2[x][crtY] = max( (i > 0 ? max2[x][ys[x][i - 1]] : -INF), dp[x][crtY] - spX[x + 1][crtY] );
        }
    }

    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++ ) {
      |                          ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 923716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 106076 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 1026460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 106076 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 24 ms 106076 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 24 ms 106076 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 Execution timed out 1098 ms 1026460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 923716 KB Time limit exceeded
2 Halted 0 ms 0 KB -