Submission #1100118

# Submission time Handle Problem Language Result Execution time Memory
1100118 2024-10-12T18:59:59 Z andrei_iorgulescu Olympiads (BOI19_olympiads) C++14
100 / 100
25 ms 3992 KB
#include <bits/stdc++.h>

using namespace std;

int n, k, c;
int a[2005][10];
vector<int> ind[10];

struct cmp
{
    bool operator ()(vector<int> A, vector<int> B) const{
        int s1 = 0, s2 = 0;
        for (int i = 0; i < k; i++)
            s1 += a[ind[i + 1][A[i]]][i + 1], s2 += a[ind[i + 1][B[i]]][i + 1];
        return s1 < s2;
        }
};

int C(int x, int y)
{
    if (y == 0)
        return 1;
    if (x < y)
        return 0;
    long long ww = 1;
    for (int i = x; i > x - y; i--)
        ww *= i;
    for (int i = 1; i <= y; i++)
        ww /= i;
    if (ww >= (int)1e9)
        ww = (int)1e9;
    return ww;
}

int cnt(vector<int> nod)
{
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < k; j++)
        {
            if (i == j)
                continue;
            int cn1 = ind[i + 1][nod[i]], cn2 = ind[j + 1][nod[j]];
            if (a[cn1][j + 1] > a[cn2][j + 1] or (a[cn1][j + 1] == a[cn2][j + 1] and cn1 < cn2))
                return 0;
        }
    }
    set<int> oameni;
    for (int i = 0; i < k; i++)
        oameni.insert(ind[i + 1][nod[i]]);
    int lft = k - (int)oameni.size();
    int cati = 0;
    for (int i = 1; i <= n; i++)
    {
        bool ok = true;
        for (int j = 1; j <= k; j++)
        {
            int cn = ind[j][nod[j - 1]];
            if (a[i][j] > a[cn][j] or (a[i][j] == a[cn][j] and i <= cn))
                ok = false;
        }
        if (ok)
            cati++;
    }
    int ans = C(cati, lft);
    return ans;
}

int main()
{
    cin >> n >> k >> c;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= k; j++)
            cin >> a[i][j];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= k; j++)
            ind[j].push_back(i);
    for (int i = 1; i <= k; i++)
    {
        sort(ind[i].begin(), ind[i].end(), [i](int A, int B)
        {
            if (a[A][i] != a[B][i])
            {return a[A][i] > a[B][i];}
            else{return A < B;}
        });
    }
    /*for (int i = 1; i <= k; i++)
    {
        cout << i << " -> ";
        for (auto it : ind[i])
            cout << it << ' ';
        cout << endl;
    }*/
    priority_queue<vector<int>, vector<vector<int>>, cmp> pq;
    int cate = 0;
    vector<int> si;
    for (int i = 1; i <= k; i++)
        si.push_back(0);
    pq.push(si);
    map<vector<int>, bool> viz;
    while (!pq.empty())
    {
        vector<int> nod = pq.top();
        pq.pop();
        int s = 0;
        for (int i = 0; i < k; i++)
            s += a[ind[i + 1][nod[i]]][i + 1];
        /*for (auto it : nod)
            cout << it << ' ';
        cout << " -> " << cnt(nod) << endl;*/
        cate += cnt(nod);
        if (cate >= c)
        {
            cout << s;
            return 0;
        }
        for (int i = 0; i < k; i++)
        {
            vector<int> nod2 = nod;
            nod2[i]++;
            if (nod2[i] < n and !viz[nod2])
                pq.push(nod2), viz[nod2] = true;
        }
    }
    return 0;
}

/*
5 2 10
1 7
2 5
3 10
4 8
2 9
*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 4 ms 1116 KB Output is correct
3 Correct 6 ms 1372 KB Output is correct
4 Correct 7 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 18 ms 1884 KB Output is correct
4 Correct 25 ms 2128 KB Output is correct
5 Correct 15 ms 2196 KB Output is correct
6 Correct 21 ms 3992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 6 ms 1372 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 18 ms 1884 KB Output is correct
12 Correct 25 ms 2128 KB Output is correct
13 Correct 15 ms 2196 KB Output is correct
14 Correct 21 ms 3992 KB Output is correct
15 Correct 16 ms 1116 KB Output is correct
16 Correct 6 ms 860 KB Output is correct
17 Correct 21 ms 2360 KB Output is correct
18 Correct 19 ms 1884 KB Output is correct
19 Correct 1 ms 348 KB Output is correct