Submission #1003802

# Submission time Handle Problem Language Result Execution time Memory
1003802 2024-06-20T17:57:34 Z amine_aroua Olympiads (BOI19_olympiads) C++17
100 / 100
23 ms 13696 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define int long long
#define pb push_back
#define nl '\n'
#define fore(i, y) for(int i = 0; i < y; i++)
#define forr(i, x, y) for(int i = x;i<=y;i++)
#define forn(i, y, x) for(int i = y; i >= x; i--)
int n , k , c;
vector<vector<int>> events;
void sort(vector<int> &v)
{
    fore(i , k)
    {
        forr(j , i + 1 , (int)v.size() - 1)
        {
            if(events[v[j]][i] > events[v[i]][i])
                swap(v[i] , v[j]);
        }
    }
}
int val(vector<int> &v)
{
    int cur = 0;
    fore(j , k)
    {
        int mx = 0;
        fore(i , k)
        {
            mx = max(mx , events[v[i]][j]);
        }
        cur+=mx;
    }
    return cur;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k>>c;
    vector<int> cur;
    events.assign(n , vector<int>(k));
    priority_queue<tuple<int , int , vector<int>>> pq;
    fore(i , n)
    {
        cur.pb(i);
        fore(j , k)
        {
            cin>>events[i][j];
        }
    }
    sort(cur);
    pq.push({val(cur), 0 , cur});
    while(c--)
    {
        auto [score , p , vec] = pq.top();
        if(c == 0)
        {
            cout<<score<<nl;
            return 0;
        }
        pq.pop();
        if((int)vec.size() == k)
            continue;
        forr(i , p , k - 1)
        {
            vector<int> nxt = vec;
            nxt.erase(nxt.begin() + i);
            sort(nxt);
            pq.push({val(nxt) , i , nxt});
        }
    }
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 4 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 2 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 20 ms 9580 KB Output is correct
4 Correct 19 ms 9016 KB Output is correct
5 Correct 10 ms 1884 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 20 ms 9580 KB Output is correct
12 Correct 19 ms 9016 KB Output is correct
13 Correct 10 ms 1884 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 12 ms 2908 KB Output is correct
16 Correct 15 ms 8284 KB Output is correct
17 Correct 23 ms 13696 KB Output is correct
18 Correct 19 ms 7852 KB Output is correct
19 Correct 4 ms 600 KB Output is correct