Submission #399233

# Submission time Handle Problem Language Result Execution time Memory
399233 2021-05-05T13:02:16 Z daanolav Carnival Tickets (IOI20_tickets) C++14
0 / 100
16 ms 556 KB
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <algorithm>

/*
2 3 2
0 2 5
1 1 3


*/

using namespace std;

#define INF 1<<29
#define MAXN 301
#define MAXM 301

typedef vector<int> vi;
typedef vector<vi> vvi;

int n,m,k,temp;

vvi x;

long getScore(vi tickets) {
    int median = tickets.at(tickets.size() / 2);
    int score = 0;
    for(int num : tickets) {
        score += abs(num - median);
    }
    return score;
}

long getBest(vvi x,int curRound, int curColor,vi curTickets,int curScore) {
    if(curColor >= n) {
        curScore += getScore(curTickets);
        if(curRound >= (k - 1)) {
            return curScore;
        }
        return getBest(x,curRound + 1,0,vi(),curScore);
    }

    int best = -1;
    for(int i = 0; i < x[curColor].size(); ++i) {
        int num = x[curColor][i];
        int insertIndex = lower_bound(curTickets.begin(),curTickets.end(),num) - curTickets.begin();
        curTickets.insert(curTickets.begin() + insertIndex,num);
        x[curColor].erase(x[curColor].begin() + i);
        int score = getBest(x,curRound,curColor + 1,curTickets,curScore);
        if(score > best) {
            best = score;
        }
        x[curColor].insert(x[curColor].begin() + insertIndex,num);
        curTickets.erase(curTickets.begin() + insertIndex);
    }

    return best;
}

long find_maximum(int k, vvi x) {
    ::k = k;
    n = x.size();
    m = x.at(0).size();
    return getBest(x,0,0,vi(),0);
}


/*
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> k;

    for(int i = 0; i < n; ++i) {
        x.push_back(vi());
        for(int j = 0; j < m; ++j) {
            cin >> temp;
            x[i].push_back(temp);
        }
    }

    cout << find_maximum(k,x);


    return 0;
}
*/

Compilation message

tickets.cpp: In function 'long int getBest(vvi, int, int, vi, int)':
tickets.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i = 0; i < x[curColor].size(); ++i) {
      |                    ~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB WA in grader: failure to call allocate_tickets
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 556 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -