Submission #479811

# Submission time Handle Problem Language Result Execution time Memory
479811 2021-10-13T08:41:31 Z stefantaga Carnival Tickets (IOI20_tickets) C++14
0 / 100
2 ms 1308 KB
#include "tickets.h"
#include <cassert>
#include <cstdio>
#include <vector>
#include <string>
#include <bits/stdc++.h>

using namespace std;
int fr[1505];
deque <pair <int,int> > ceaules[1505];
vector <vector <int> > matrfin;
long long find_maximum(int k, std::vector<std::vector<int>> x)
{
    int i,j;
    int n = x.size();
    int m = x[0].size();
    for (i=0; i<n; i++)
    {
        for (j=0; j<m; j++)
        {
            ceaules[i].push_back({x[i][j],j});
        }
    }
    matrfin.resize(n);
    for (i=0;i<n;i++)
    {
        matrfin[i].resize(m);
    }
    long long solfin=0;
    for (i=1; i<=k; i++)
    {
        vector <pair <int,pair <int,int> >> bonjour;
        for (j=0; j<n; j++)
        {
            fr[j]=0;
            bonjour.push_back({ceaules[j].front().first,{ceaules[j].front().second,j}});
            bonjour.push_back({ceaules[j].back().first,{ceaules[j].back().second,j}});
        }
        sort (bonjour.begin(),bonjour.end());
        int cateiau=n/2;
        long long sum=0;
        for (j=2*n-1; j>=(2*n-cateiau); j--)
        {
            fr[bonjour[j].second.second]=1;
            int loc=bonjour[j].second.second;
            matrfin[loc][bonjour[j].second.first]=i;
            if (bonjour[j].first==ceaules[loc].front().first)
            {
                ceaules[loc].pop_front();
            }
            else
            {
                ceaules[loc].pop_back();
            }
            sum=sum+bonjour[j].first;
        }
        for (j=0; j<2*n; j++)
        {
            int loc=bonjour[j].second.second;
            if (fr[loc]==0)
            {
                fr[loc]=1;
                matrfin[loc][bonjour[j].second.first]=i;
                if (bonjour[j].first==ceaules[loc].front().first)
                {
                    ceaules[loc].pop_front();
                }
                else
                {
                    ceaules[loc].pop_back();
                }
                sum=sum-bonjour[j].first;
                cateiau--;
                if (cateiau==0)
                {
                    break;
                }
            }
        }
        solfin=solfin+sum;
    }
    for (i=0;i<n;i++)
    {
        for (j=0;j<m;j++)
        {
            matrfin[i][j]--;
        }
    }
    allocate_tickets(matrfin);
    return solfin;
}
#ifdef HOME
static int n;
static int m;
static int k;
static std::vector<std::vector<int>> d;
static std::vector<std::vector<int>> x;
static int called = 0;

static void check(bool cond, std::string message)
{
    if (!cond)
    {
        printf("%s\n", message.c_str());
        exit(0);
    }
}


void allocate_tickets( std::vector<std::vector<int>> _d)
{
    check(!called, "allocate_tickets called more than once");
    d = _d;
    check((int)d.size() == n, "allocate_tickets called with parameter of wrong size");
    for (int i = 0; i < n; i++)
    {
        check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size");
    }
    called = 1;
}

int main()
{
    assert(scanf("%d %d %d", &n, &m, &k) == 3);
    x.resize(n);
    for (int i = 0; i < n; i++)
    {
        x[i].resize(m);
        for (int j=0; j < m; j++)
        {
            assert(scanf("%d", &x[i][j]) == 1);
        }
    }
    fclose(stdin);

    long long answer = find_maximum(k, x);
    check(called, "failure to call allocate_tickets");
    printf("%lld\n", answer);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (j) printf(" ");
            printf("%d", d[i][j]);
        }
        printf("\n");
    }
    fclose(stdout);
    return 0;
}

#endif // HOME
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Incorrect 1 ms 1228 KB There is no ticket of color 5 on day 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Incorrect 2 ms 1228 KB Contestant returned 4550041251 while correct return value is 4564307189.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1228 KB There is no ticket of color 0 on day 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1228 KB There is no ticket of color 1 on day 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1228 KB There is no ticket of color 1 on day 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1228 KB There is no ticket of color 1 on day 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Incorrect 1 ms 1228 KB There is no ticket of color 5 on day 0
3 Halted 0 ms 0 KB -