Submission #974565

# Submission time Handle Problem Language Result Execution time Memory
974565 2024-05-03T13:12:01 Z LucaIlie Carnival Tickets (IOI20_tickets) C++17
0 / 100
1 ms 2652 KB
#include "tickets.h"
#include <bits/stdc++.h>

using namespace std;

struct cell {
    int i, j, val;
};

const int MAX_N = 1500;
const int MAX_M = 1500;
const long long INF = 1e15;
int x[MAX_N + 1][MAX_M + 1];
long long sx[MAX_N + 1][MAX_M + 1];
vector<int> mins[MAX_N + 1], maxs[MAX_N + 1], minTake[MAX_N + 1], maxTake[MAX_N + 1];
bool isMax[MAX_N + 1];
vector<cell> opt;

long long find_maximum( int k, vector<vector<int>> X ) {
    int n = X.size();
    int m = X[0].size();
    vector<vector<int>> answer( n );
    long long sum = 0;

    for ( int i = 1; i <= n; i++ ) {
        answer[i - 1].resize( m );
        for ( int j = 1; j <= m; j++ ) {
            x[i][j] = X[i - 1][j - 1];
            sx[i][j] = sx[i][j - 1] + x[i][j];
            answer[i - 1][j - 1] = -1;
        }
    }

    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= k; j++ ) {
            mins[i].push_back( j );
            opt.push_back( { i, m - (k - j), x[i][j] + x[i][m - (k - j)] } );
        }
    }

    sort( opt.begin(), opt.end(), []( cell a, cell b ) { return a.val > b.val; } );
    for ( int i = 0; i < n * k / 2; i++ ) {
        mins[opt[i].i].pop_back();
        maxs[opt[i].i].push_back( opt[i].j );
    }

    for ( int i = 1; i <= n; i++ )
        reverse( mins[i].begin(), mins[i].end() );

    for ( int pas = 0; pas < k; pas++ ) {
        for ( int i = 1; i <= n; i++ )
            isMax[i] = false;

        vector<pair<int, int>> maxx;
        for ( int i = 1; i <= n; i++ ) {
            if ( !maxs[i].empty() )
                maxx.push_back( { (mins[i].empty() ? 0 : x[i][maxs[i].back()]), i } );
        }
        sort( maxx.begin(), maxx.end() );
        for ( int i = 0; i < n / 2; i++ ) {
            isMax[maxx[i].second] = true;
            if ( maxs[maxx[i].second].back() > m || answer[maxx[i].second - 1][maxs[maxx[i].second].back() - 1] != -1 )
                exit( 1 );
            answer[maxx[i].second - 1][maxs[maxx[i].second].back() - 1] = pas;
            sum += x[maxx[i].second][maxs[maxx[i].second].back()];
            maxs[maxx[i].second].pop_back();
        }
        for ( int i = 1; i <= n; i++ ) {
            if ( isMax[i] )
                continue;
            isMax[i] = true;
            if ( mins[i].empty() )
                exit( 1 );
            //answer[i - 1][mins[i].back() - 1] = pas;
            sum -= x[i][mins[i].back()];
            mins[i].pop_back();
        }
        for ( int i = 1; i <= n; i++ ) {
            if ( !isMax[i] )
                exit( 1 );
        }
    }

    allocate_tickets( answer );
    return sum;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB There is no ticket of color 0 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB There is no ticket of color 0 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB There is no ticket of color 0 on day 2
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB There is no ticket of color 0 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB There is no ticket of color 0 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB There is no ticket of color 0 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB There is no ticket of color 0 on day 0
2 Halted 0 ms 0 KB -