답안 #858814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858814 2023-10-09T08:30:27 Z LucaIlie 메기 농장 (IOI22_fish) C++17
9 / 100
1000 ms 552760 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[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++ ) {
        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++ ) {
        for ( int i = 0; i < ys[x].size(); i++ ) {
            int crtY = ys[x][i];
            dp[x][crtY] = dpLower[x][crtY] = -INF;

            if ( x >= 1 ) {
                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], maxPref1[x - 1][prevY] + spX[x - 1][crtY] );
                    dp[x][crtY] = max( dp[x][crtY], maxPref1[x - 1][prevY] + spX[x - 1][crtY] );
                }
                if ( upper != ys[x - 1].end() ) {
                    int prevY = *upper;
                    dp[x][crtY] = max( dp[x][crtY], maxSuf2[x - 1][prevY] - spX[x][crtY] );
                }
            }

            if ( x >= 2 ) {
                auto lower = upper_bound( ys[x - 2].begin(), ys[x - 2].end(), crtY );
                auto upper = lower_bound( ys[x - 2].begin(), ys[x - 2].end(), crtY );
                if ( lower != ys[x - 2].begin() ) {
                    lower--;
                    int prevY = *lower;
                    dpLower[x][crtY] = max( dpLower[x][crtY], maxPref3[x - 2][prevY] + spX[x - 1][crtY] );
                    dp[x][crtY] = max( dp[x][crtY], maxPref3[x - 2][prevY] + spX[x - 1][crtY] );
                }
                if ( upper != ys[x - 2].end() ) {
                    int prevY = *upper;
                    dpLower[x][crtY] = max( dpLower[x][crtY], maxSuf2[x - 2][prevY] );
                    dp[x][crtY] = max( dp[x][crtY], maxSuf2[x - 2][prevY] );
                }
            }

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

        for ( int i = 1; i < ys[x].size(); i++ ) {
            maxPref1[x][ys[x][i]] = max( maxPref1[x][ys[x][i]], maxPref1[x][ys[x][i - 1]] );
            maxPref3[x][ys[x][i]] = max( maxPref3[x][ys[x][i]], maxPref3[x][ys[x][i - 1]] );
        }
        for ( int i = ys[x].size() - 2; i >= 0; i-- )
            maxSuf2[x][ys[x][i]] = max( maxSuf2[x][ys[x][i]], maxSuf2[x][ys[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:33:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for ( int i = 0; i < ys[x].size(); i++ )
      |                          ~~^~~~~~~~~~~~~~
fish.cpp:35:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for ( int i = 0; i < ys[x - 1].size(); i++ )
      |                          ~~^~~~~~~~~~~~~~~~~~
fish.cpp:37:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for ( int i = 0; i < ys[x + 1].size(); i++ )
      |                          ~~^~~~~~~~~~~~~~~~~~
fish.cpp:41:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         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:87:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for ( int i = 1; i < ys[x].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 255252 KB Output is correct
2 Correct 426 ms 285312 KB Output is correct
3 Correct 178 ms 210004 KB Output is correct
4 Correct 181 ms 210228 KB Output is correct
5 Execution timed out 1069 ms 552760 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 122456 KB Output is correct
2 Correct 550 ms 296008 KB Output is correct
3 Correct 619 ms 320244 KB Output is correct
4 Correct 376 ms 255376 KB Output is correct
5 Correct 421 ms 285368 KB Output is correct
6 Correct 28 ms 122460 KB Output is correct
7 Correct 29 ms 122456 KB Output is correct
8 Correct 28 ms 122524 KB Output is correct
9 Correct 28 ms 122460 KB Output is correct
10 Correct 169 ms 210152 KB Output is correct
11 Correct 183 ms 210204 KB Output is correct
12 Correct 461 ms 278004 KB Output is correct
13 Correct 557 ms 316796 KB Output is correct
14 Correct 421 ms 266592 KB Output is correct
15 Correct 393 ms 263392 KB Output is correct
16 Correct 442 ms 266972 KB Output is correct
17 Runtime error 195 ms 285272 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 210040 KB Output is correct
2 Correct 172 ms 210256 KB Output is correct
3 Correct 264 ms 222032 KB Output is correct
4 Correct 251 ms 226160 KB Output is correct
5 Correct 375 ms 245328 KB Output is correct
6 Correct 374 ms 245332 KB Output is correct
7 Correct 377 ms 245200 KB Output is correct
8 Correct 384 ms 245212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 122456 KB Output is correct
2 Correct 28 ms 122460 KB Output is correct
3 Correct 27 ms 122356 KB Output is correct
4 Correct 27 ms 122448 KB Output is correct
5 Correct 28 ms 122456 KB Output is correct
6 Correct 27 ms 122460 KB Output is correct
7 Correct 28 ms 122960 KB Output is correct
8 Correct 27 ms 122456 KB Output is correct
9 Correct 28 ms 122716 KB Output is correct
10 Correct 31 ms 123228 KB Output is correct
11 Correct 28 ms 122972 KB Output is correct
12 Incorrect 30 ms 123224 KB 1st lines differ - on the 1st token, expected: '450122905247', found: '449292121903'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 122456 KB Output is correct
2 Correct 28 ms 122460 KB Output is correct
3 Correct 27 ms 122356 KB Output is correct
4 Correct 27 ms 122448 KB Output is correct
5 Correct 28 ms 122456 KB Output is correct
6 Correct 27 ms 122460 KB Output is correct
7 Correct 28 ms 122960 KB Output is correct
8 Correct 27 ms 122456 KB Output is correct
9 Correct 28 ms 122716 KB Output is correct
10 Correct 31 ms 123228 KB Output is correct
11 Correct 28 ms 122972 KB Output is correct
12 Incorrect 30 ms 123224 KB 1st lines differ - on the 1st token, expected: '450122905247', found: '449292121903'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 122456 KB Output is correct
2 Correct 28 ms 122460 KB Output is correct
3 Correct 27 ms 122356 KB Output is correct
4 Correct 27 ms 122448 KB Output is correct
5 Correct 28 ms 122456 KB Output is correct
6 Correct 27 ms 122460 KB Output is correct
7 Correct 28 ms 122960 KB Output is correct
8 Correct 27 ms 122456 KB Output is correct
9 Correct 28 ms 122716 KB Output is correct
10 Correct 31 ms 123228 KB Output is correct
11 Correct 28 ms 122972 KB Output is correct
12 Incorrect 30 ms 123224 KB 1st lines differ - on the 1st token, expected: '450122905247', found: '449292121903'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 210040 KB Output is correct
2 Correct 172 ms 210256 KB Output is correct
3 Correct 264 ms 222032 KB Output is correct
4 Correct 251 ms 226160 KB Output is correct
5 Correct 375 ms 245328 KB Output is correct
6 Correct 374 ms 245332 KB Output is correct
7 Correct 377 ms 245200 KB Output is correct
8 Correct 384 ms 245212 KB Output is correct
9 Correct 632 ms 298612 KB Output is correct
10 Correct 264 ms 196696 KB Output is correct
11 Correct 550 ms 271284 KB Output is correct
12 Correct 30 ms 122460 KB Output is correct
13 Correct 30 ms 122712 KB Output is correct
14 Correct 27 ms 122348 KB Output is correct
15 Correct 27 ms 122460 KB Output is correct
16 Correct 27 ms 122456 KB Output is correct
17 Correct 27 ms 122460 KB Output is correct
18 Correct 180 ms 210000 KB Output is correct
19 Correct 174 ms 210304 KB Output is correct
20 Correct 165 ms 210004 KB Output is correct
21 Correct 167 ms 210120 KB Output is correct
22 Incorrect 630 ms 299112 KB 1st lines differ - on the 1st token, expected: '45561826463480', found: '44138711368485'
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 255252 KB Output is correct
2 Correct 426 ms 285312 KB Output is correct
3 Correct 178 ms 210004 KB Output is correct
4 Correct 181 ms 210228 KB Output is correct
5 Execution timed out 1069 ms 552760 KB Time limit exceeded
6 Halted 0 ms 0 KB -