Submission #1004874

# Submission time Handle Problem Language Result Execution time Memory
1004874 2024-06-21T21:03:07 Z MarwenElarbi Olympiads (BOI19_olympiads) C++17
100 / 100
28 ms 7112 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=5e2+5;
int tab[2005][6];
int n,k,c;
void compare(vector<int> &v){
    for (int i = 0; i < k; ++i)
    {
        for (int j = i+1; j < (int)v.size(); ++j)
        {
            if(tab[v[j]][i]>tab[v[i]][i]) swap(v[i],v[j]);
        }
    }
    return;
}
int val(vector<int> &v){
    int sum=0;
    for (int i = 0; i < k; ++i)
    {
        int mx=0;
        for (int j = 0; j < k; ++j)
        {
            mx=max(mx,tab[v[j]][i]);
        }
        sum+=mx;
    }
    return sum;
}
int main()
{
    cin>>n>>k>>c;
    vector<int> cur;
    for (int i = 0; i < n; ++i)
    {
        cur.pb(i);
        for (int j = 0; j < k; ++j)
        {
            cin>>tab[i][j];
        }
    }
    compare(cur);
    priority_queue<tuple<int,int,vector<int>>> pq;
    pq.push({val(cur),0,cur});
    while(c--){
        auto [ans,pos,v] = pq.top();
        //cout <<ans<<" "<<pos<<" "<<v.size()<<endl;
        pq.pop();
        if(c==0){
            cout << ans<<endl;
            return 0;
        }
        if(v.size()==k) continue;
        for (int i = pos; i < k; ++i)
        {
            vector<int> nxt=v;
            nxt.erase(nxt.begin()+i);
            compare(nxt);
            pq.push({val(nxt),i,nxt});
        }
    }
}

Compilation message

olympiads.cpp: In function 'int main()':
olympiads.cpp:59:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |         if(v.size()==k) continue;
      |            ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 5 ms 576 KB Output is correct
3 Correct 15 ms 4952 KB Output is correct
4 Correct 14 ms 4700 KB Output is correct
5 Correct 5 ms 1112 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 5 ms 600 KB Output is correct
10 Correct 5 ms 576 KB Output is correct
11 Correct 15 ms 4952 KB Output is correct
12 Correct 14 ms 4700 KB Output is correct
13 Correct 5 ms 1112 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 12 ms 1560 KB Output is correct
16 Correct 12 ms 4444 KB Output is correct
17 Correct 28 ms 7112 KB Output is correct
18 Correct 18 ms 4284 KB Output is correct
19 Correct 5 ms 348 KB Output is correct