답안 #1104384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104384 2024-10-23T14:29:01 Z alexdd Olympiads (BOI19_olympiads) C++17
44 / 100
2000 ms 178892 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);
        sort(alesi.begin(),alesi.end());
        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);
        sort(alesi.begin(),alesi.end());
        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)
{
    if(x.sumval < y.sumval)
        return 1;
    if(x.sumval > y.sumval)
        return 0;
    if((int)x.alesi.size() < (int)y.alesi.size())
        return 1;
    if((int)x.alesi.size() > (int)y.alesi.size())
        return 0;
    //sort(x.alesi.begin(),x.alesi.end());
    //sort(y.alesi.begin(),y.alesi.end());
    for(int i=0;i<x.alesi.size();i++)
    {
        if(x.alesi[i] < y.alesi[i])
            return 1;
        if(x.alesi[i] > y.alesi[i])
            return 0;
    }
    return 0;
}
bool ales[505];
config init;
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);
    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;
            }
        }
        assert(unde!=-1);
        ales[unde] = 1;
        init.baga(unde);
    }
    priority_queue<config> pq;
    map<config,int> inq;
    pq.push(init);
    inq[init]=1;
    int cnt=0;
    int prec=1e9;
    while(!pq.empty())
    {
        config aux = pq.top();
        pq.pop();
        /*for(int i=0;i<aux.alesi.size();i++)
            cerr<<aux.alesi[i]<<" ";
        cerr<<" zzz\n";*/
        assert(aux.sumval <= prec);
        prec = aux.sumval;
        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:24: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]
   24 |         for(int i=0;i<alesi.size();i++)
      |                     ~^~~~~~~~~~~~~
olympiads.cpp: In function 'bool operator<(config, config)':
olympiads.cpp:64:18: 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]
   64 |     for(int i=0;i<x.alesi.size();i++)
      |                 ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1961 ms 36516 KB Output is correct
2 Correct 1930 ms 36220 KB Output is correct
3 Correct 1957 ms 36308 KB Output is correct
4 Correct 1494 ms 8932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 497 ms 32984 KB Output is correct
2 Correct 448 ms 29984 KB Output is correct
3 Correct 490 ms 31436 KB Output is correct
4 Correct 503 ms 29916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2048 ms 178892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1961 ms 36516 KB Output is correct
2 Correct 1930 ms 36220 KB Output is correct
3 Correct 1957 ms 36308 KB Output is correct
4 Correct 1494 ms 8932 KB Output is correct
5 Correct 497 ms 32984 KB Output is correct
6 Correct 448 ms 29984 KB Output is correct
7 Correct 490 ms 31436 KB Output is correct
8 Correct 503 ms 29916 KB Output is correct
9 Execution timed out 2048 ms 178892 KB Time limit exceeded
10 Halted 0 ms 0 KB -