Submission #1104368

# Submission time Handle Problem Language Result Execution time Memory
1104368 2024-10-23T14:05:33 Z alexdd Olympiads (BOI19_olympiads) C++17
0 / 100
1224 ms 8512 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,k,c;
int a[505][7];
struct config
{
    int val[7],sumval;
    vector<int> alesi;
    void baga(int x)
    {
        alesi.push_back(x);
        sumval=0;
        for(int i=1;i<=k;i++)
        {
            val[i] = max(val[i], a[x][i]);
            sumval += val[i];
        }
    }
    void scoate(int x)
    {
        bool gasit=0;
        for(int i=0;i<alesi.size();i++)
        {
            if(alesi[i]==x)
            {
                gasit=1;
                alesi.erase(alesi.begin()+i);
                break;
            }
        }
        assert(gasit);
        sumval=0;
        for(int i=1;i<=k;i++)
        {
            val[i]=0;
            for(int j:alesi)
                val[i] = max(val[i], a[j][i]);
            sumval += val[i];
        }
    }
    bool is_ales(int x)
    {
        for(int i:alesi)
            if(i==x)
                return 1;
        return 0;
    }
};
bool operator<(config x, config y)
{
    return x.sumval < y.sumval;
}
bool ales[505];
signed main()
{
    cin>>n>>k>>c;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            cin>>a[i][j];
        }
    }
    assert(k<=n);
    config init;
    for(int i=1;i<=k;i++)
    {
        int mxm=-1,unde=-1;
        for(int j=1;j<=n;j++)
        {
            if(!ales[j] && a[j][i]>mxm)
            {
                mxm = a[j][i];
                unde = j;
            }
        }
        ales[unde] = 1;
        init.baga(unde);
    }
    priority_queue<config> pq;
    map<config,int> inq;
    pq.push(init);
    inq[init]=1;
    int cnt=0;
    while(!pq.empty())
    {
        config aux = pq.top();
        pq.pop();
        cnt++;
        if(cnt==c)
        {
            cout<<aux.sumval;
            return 0;
        }
        for(int s:aux.alesi)
        {
            for(int i=1;i<=n;i++)
            {
                if(!aux.is_ales(i))
                {
                    config newc = aux;
                    newc.scoate(s);
                    newc.baga(i);
                    if(!inq[newc])
                    {
                        pq.push(newc);
                        inq[newc]=1;
                    }
                }
            }
        }
    }
    assert(0==1);
    return 0;
}
/*
5 4 4
7 0 4 9
3 0 8 4
1 1 3 7
5 1 3 4
4 2 2 9
*/

Compilation message

olympiads.cpp: In member function 'void config::scoate(long long int)':
olympiads.cpp:23:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int i=0;i<alesi.size();i++)
      |                     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1224 ms 7536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 245 ms 8512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1224 ms 7536 KB Output isn't correct
2 Halted 0 ms 0 KB -