답안 #950609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950609 2024-03-20T13:39:50 Z LOLOLO Olympiads (BOI19_olympiads) C++17
100 / 100
4 ms 1368 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 510;
int n, k, c;
int cc[N][10], rnk[10][N], id;

bool cmp(int a, int b) {
    return cc[a][id] > cc[b][id];
}

struct node{
    bitset <510> ban;
    vector <int> used;
    ll sum = 0, id;

    void calculate(int _id, bitset<510> _ban) {
        id = _id;
        ban = _ban;
        for (int j = 1; j <= k; j++) {
            for (int i = 1; i <= n; i++) {
                if (ban[rnk[j][i]] == 0) {
                    used.pb(rnk[j][i]);
                    ban[rnk[j][i]] = 1;
                    break;
                }
            }
        }

        vector <int> score(k + 1, 0);
        for (auto x : used) {
            for (int i = 1; i <= k; i++)
                score[i] = max(score[i], cc[x][i]);
        }

        for (int i = 1; i <= k; i++)
            sum += score[i];

        for (auto x : used)
            ban[x] = 0;
    }    
};

bool operator<(const node& A, const node& B) {
    return A.sum < B.sum;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k >> c;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            cin >> cc[i][j];
        }
    }

    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= n; j++)
            rnk[i][j] = j;

        id = i;
        sort(rnk[i] + 1, rnk[i] + 1 + n, cmp);
    }

    bitset <510> bt;
    node ss;
    ss.calculate(0, bt);
    priority_queue <node> pq;
    pq.push(ss);

    ll ans = 0;
    for (int i = 1; i <= c; i++) {
        auto t = pq.top();
        pq.pop();
        ans = t.sum;
        int id = t.id;
        auto ban = t.ban;
        while (id < k) {
            ban[t.used[id]] = 1;
            node ss;
            ss.calculate(id, ban);
            ban[t.used[id]] = 0;
            if (sz(ss.used) == k) {
                pq.push(ss);
            }
            id++;
        }
    }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 3 ms 1068 KB Output is correct
4 Correct 2 ms 812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 1068 KB Output is correct
4 Correct 3 ms 1008 KB Output is correct
5 Correct 4 ms 1064 KB Output is correct
6 Correct 2 ms 812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 1068 KB Output is correct
8 Correct 2 ms 812 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 3 ms 1068 KB Output is correct
12 Correct 3 ms 1008 KB Output is correct
13 Correct 4 ms 1064 KB Output is correct
14 Correct 2 ms 812 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 4 ms 1068 KB Output is correct
17 Correct 4 ms 1368 KB Output is correct
18 Correct 4 ms 808 KB Output is correct
19 Correct 2 ms 344 KB Output is correct