Submission #561449

# Submission time Handle Problem Language Result Execution time Memory
561449 2022-05-12T20:23:54 Z OttoTheDino Olympiads (BOI19_olympiads) C++17
100 / 100
389 ms 25728 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)                  for (int i = s; i <= e; ++i)
#define rrep(i,s,e)                 for (int i = s; i >= e; --i)
#define pb                          push_back
#define pf                          push_front
#define fi                          first
#define se                          second
#define all(a)                      a.begin(), a.end()
#define len(a)                      (int)a.size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;

const int mx = 1e6;

map<vi,bool> mp;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, k, r; cin >> n >> k >> r;

    vi c[k];
    int a[n][k], b[k][mx+1] = {};

    rep (i,0,n-1) {
        rep (j,0,k-1) {
            cin >> a[i][j];
            if (!b[j][a[i][j]]) {
                b[j][a[i][j]] = 1;
                c[j].pb(a[i][j]);
            }
        }
    }

    priority_queue<pair<int,vi>> pq;

    int s = 0;
    vi v;
    rep (i,0,k-1) {
        sort(all(c[i]), greater<int>());
        s += c[i][0];
        v.pb(0);
    }

    pq.push({s, v});

    int x = 0;

    while (!pq.empty()) {
        s = pq.top().fi;
        v = pq.top().se;
        pq.pop();

        int dp[k+1][1<<k] = {};
        dp[0][0] = 1;

        rep (i,0,n-1) {
            int cur = 0, suc = 1;
            rep (j,0,k-1) {
                if (a[i][j]==c[j][v[j]]) cur += (1<<j);
                else if (a[i][j]>c[j][v[j]]) suc = 0; 
            }
            if (suc) rrep (j,k-1,0) rep (mask,0,(1<<k)-1) dp[j+1][mask|cur] += dp[j][mask];
            if (dp[k][(1<<k)-1] > r) break;
        }

        x += dp[k][(1<<k)-1];

        if (x>=r) {
            cout << s << "\n";
            return 0;
        }

        rep (i,0,k-1) {
            ++v[i];
            if (v[i]<len(c[i]) && !mp[v]) {
                mp[v] = 1;
                pq.push({s + c[i][v[i]] - c[i][v[i]-1], v});
            }
            --v[i];
        }
    }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 9 ms 8148 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 6 ms 8100 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23876 KB Output is correct
2 Correct 28 ms 24532 KB Output is correct
3 Correct 33 ms 24776 KB Output is correct
4 Correct 36 ms 24748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 19 ms 23816 KB Output is correct
4 Correct 19 ms 23764 KB Output is correct
5 Correct 19 ms 23828 KB Output is correct
6 Correct 13 ms 23832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8148 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 6 ms 8100 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 18 ms 23876 KB Output is correct
6 Correct 28 ms 24532 KB Output is correct
7 Correct 33 ms 24776 KB Output is correct
8 Correct 36 ms 24748 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 19 ms 23816 KB Output is correct
12 Correct 19 ms 23764 KB Output is correct
13 Correct 19 ms 23828 KB Output is correct
14 Correct 13 ms 23832 KB Output is correct
15 Correct 389 ms 24652 KB Output is correct
16 Correct 115 ms 24268 KB Output is correct
17 Correct 295 ms 25728 KB Output is correct
18 Correct 381 ms 25292 KB Output is correct
19 Correct 14 ms 23764 KB Output is correct