Submission #858841

# Submission time Handle Problem Language Result Execution time Memory
858841 2023-10-09T09:00:13 Z LucaIlie Catfish Farm (IOI22_fish) C++17
9 / 100
603 ms 301908 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], maxPref1[MAX_N], maxSuf2[MAX_N], maxPref3[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[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++ ) {
        vector<int> yss;
        for ( int i = 0; i < ys[x].size(); i++ )
            yss.push_back( ys[x][i] );
        for ( int i = 0; i < ys[x - 1].size(); i++ )
            yss.push_back( ys[x - 1][i] );
        for ( int i = 0; i < ys[x + 1].size(); i++ )
            yss.push_back( ys[x + 1][i] );
        sort( yss.begin(), yss.end() );
        yss.resize( unique( yss.begin(), yss.end() ) - yss.begin() );
        for ( int i = 1; i < yss.size(); i++ )
            spX[x][yss[i]] = spX[x][yss[i - 1]] + costCell[x][yss[i]];
    }

    dp[0][0] = dpLower[0][0] = 0;
    for ( int x = 1; x <= n + 1; x++ ) {
        int lower1 = 0, upper1 = 0, lower2 = 0, upper2 = 0;
        for ( int i = 0; i < ys[x].size(); i++ ) {
            int crtY = ys[x][i];
            dp[x][i] = dpLower[x][i] = -INF;

            if ( x >= 1 ) {
                while ( lower1 + 1 < ys[x - 1].size() && ys[x - 1][lower1 + 1] <= crtY )
                    lower1++;
                while ( upper1 < ys[x - 1].size() && ys[x - 1][upper1] < crtY )
                    upper1++;

                if ( lower1 >= 0 ) {
                    int prevY = ys[x - 1][lower1];
                    dpLower[x][i] = max( dpLower[x][i], maxPref1[x - 1][lower1] + spX[x - 1][crtY] );
                    dp[x][i] = max( dp[x][i], maxPref1[x - 1][lower1] + spX[x - 1][crtY] );
                }
                if ( upper1 < ys[x - 1].size() ) {
                    int prevY = ys[x - 1][upper1];
                    dp[x][i] = max( dp[x][i], maxSuf2[x - 1][upper1] - spX[x][crtY] );
                }
            }

            if ( x >= 2 ) {
                while ( lower2 + 1 < ys[x - 2].size() && ys[x - 2][lower2 + 1] <= crtY )
                    lower2++;
                while ( upper2 < ys[x - 2].size() && ys[x - 2][upper2] < crtY )
                    upper2++;

                if ( lower2 >= 0 ) {
                    int prevY = ys[x - 2][lower2];
                    dpLower[x][i] = max( dpLower[x][i], maxPref3[x - 2][lower2] + spX[x - 1][crtY] );
                    dp[x][i] = max( dp[x][i], maxPref3[x - 2][lower2] + spX[x - 1][crtY] );
                }
                if ( upper2 < ys[x - 2].size() ) {
                    int prevY = ys[x - 2][upper2];
                    dpLower[x][i] = max( dpLower[x][i], maxSuf2[x - 2][upper2] );
                    dp[x][i] = max( dp[x][i], maxSuf2[x - 2][upper2] );
                }
            }

            maxPref1[x][i] = dpLower[x][i] - spX[x][crtY];
            maxSuf2[x][i] = dp[x][i] + spX[x + 1][crtY];
            maxPref3[x][i] = dpLower[x][i];
        }

        for ( int i = 1; i < ys[x].size(); i++ ) {
            maxPref1[x][ys[x][i]] = max( maxPref1[x][i], maxPref1[x][i - 1] );
            maxPref3[x][ys[x][i]] = max( maxPref3[x][i], maxPref3[x][i - 1] );
        }
        for ( int i = ys[x].size() - 2; i >= 0; i-- )
            maxSuf2[x][ys[x][i]] = max( maxSuf2[x][i], maxSuf2[x][i + 1] );
    }

    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:32:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for ( int i = 0; i < ys[x].size(); i++ )
      |                          ~~^~~~~~~~~~~~~~
fish.cpp:34:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for ( int i = 0; i < ys[x - 1].size(); i++ )
      |                          ~~^~~~~~~~~~~~~~~~~~
fish.cpp:36:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for ( int i = 0; i < ys[x + 1].size(); i++ )
      |                          ~~^~~~~~~~~~~~~~~~~~
fish.cpp:40:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for ( int i = 1; i < yss.size(); i++ )
      |                          ~~^~~~~~~~~~~~
fish.cpp:47:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for ( int i = 0; i < ys[x].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~~
fish.cpp:52:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |                 while ( lower1 + 1 < ys[x - 1].size() && ys[x - 1][lower1 + 1] <= crtY )
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:54:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |                 while ( upper1 < ys[x - 1].size() && ys[x - 1][upper1] < crtY )
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:58:25: warning: unused variable 'prevY' [-Wunused-variable]
   58 |                     int prevY = ys[x - 1][lower1];
      |                         ^~~~~
fish.cpp:62:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                 if ( upper1 < ys[x - 1].size() ) {
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:63:25: warning: unused variable 'prevY' [-Wunused-variable]
   63 |                     int prevY = ys[x - 1][upper1];
      |                         ^~~~~
fish.cpp:69:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |                 while ( lower2 + 1 < ys[x - 2].size() && ys[x - 2][lower2 + 1] <= crtY )
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:71:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |                 while ( upper2 < ys[x - 2].size() && ys[x - 2][upper2] < crtY )
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:75:25: warning: unused variable 'prevY' [-Wunused-variable]
   75 |                     int prevY = ys[x - 2][lower2];
      |                         ^~~~~
fish.cpp:79:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |                 if ( upper2 < ys[x - 2].size() ) {
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:80:25: warning: unused variable 'prevY' [-Wunused-variable]
   80 |                     int prevY = ys[x - 2][upper2];
      |                         ^~~~~
fish.cpp:91:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for ( int i = 1; i < ys[x].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 292 ms 241912 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '5492851724'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 122460 KB Output is correct
2 Incorrect 535 ms 297448 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '4748330365'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 203 ms 210004 KB Output is correct
2 Correct 212 ms 210208 KB Output is correct
3 Correct 299 ms 222124 KB Output is correct
4 Correct 294 ms 225872 KB Output is correct
5 Correct 423 ms 245328 KB Output is correct
6 Correct 425 ms 245624 KB Output is correct
7 Correct 421 ms 245328 KB Output is correct
8 Correct 438 ms 245220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 122320 KB Output is correct
2 Correct 31 ms 122460 KB Output is correct
3 Correct 30 ms 122708 KB Output is correct
4 Correct 28 ms 122460 KB Output is correct
5 Correct 28 ms 122460 KB Output is correct
6 Correct 28 ms 122320 KB Output is correct
7 Correct 28 ms 122456 KB Output is correct
8 Correct 28 ms 122460 KB Output is correct
9 Correct 29 ms 122712 KB Output is correct
10 Correct 30 ms 123228 KB Output is correct
11 Incorrect 28 ms 122716 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '257536839824'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 122320 KB Output is correct
2 Correct 31 ms 122460 KB Output is correct
3 Correct 30 ms 122708 KB Output is correct
4 Correct 28 ms 122460 KB Output is correct
5 Correct 28 ms 122460 KB Output is correct
6 Correct 28 ms 122320 KB Output is correct
7 Correct 28 ms 122456 KB Output is correct
8 Correct 28 ms 122460 KB Output is correct
9 Correct 29 ms 122712 KB Output is correct
10 Correct 30 ms 123228 KB Output is correct
11 Incorrect 28 ms 122716 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '257536839824'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 122320 KB Output is correct
2 Correct 31 ms 122460 KB Output is correct
3 Correct 30 ms 122708 KB Output is correct
4 Correct 28 ms 122460 KB Output is correct
5 Correct 28 ms 122460 KB Output is correct
6 Correct 28 ms 122320 KB Output is correct
7 Correct 28 ms 122456 KB Output is correct
8 Correct 28 ms 122460 KB Output is correct
9 Correct 29 ms 122712 KB Output is correct
10 Correct 30 ms 123228 KB Output is correct
11 Incorrect 28 ms 122716 KB 1st lines differ - on the 1st token, expected: '278622587073', found: '257536839824'
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 203 ms 210004 KB Output is correct
2 Correct 212 ms 210208 KB Output is correct
3 Correct 299 ms 222124 KB Output is correct
4 Correct 294 ms 225872 KB Output is correct
5 Correct 423 ms 245328 KB Output is correct
6 Correct 425 ms 245624 KB Output is correct
7 Correct 421 ms 245328 KB Output is correct
8 Correct 438 ms 245220 KB Output is correct
9 Correct 603 ms 301856 KB Output is correct
10 Correct 285 ms 196968 KB Output is correct
11 Correct 588 ms 271320 KB Output is correct
12 Correct 27 ms 122460 KB Output is correct
13 Correct 28 ms 122460 KB Output is correct
14 Correct 28 ms 122460 KB Output is correct
15 Correct 27 ms 122460 KB Output is correct
16 Correct 27 ms 122456 KB Output is correct
17 Correct 28 ms 122500 KB Output is correct
18 Correct 205 ms 210128 KB Output is correct
19 Correct 204 ms 210144 KB Output is correct
20 Correct 202 ms 210036 KB Output is correct
21 Correct 209 ms 210012 KB Output is correct
22 Incorrect 599 ms 301908 KB 1st lines differ - on the 1st token, expected: '45561826463480', found: '36845835522844'
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 292 ms 241912 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '5492851724'
2 Halted 0 ms 0 KB -