Submission #715782

# Submission time Handle Problem Language Result Execution time Memory
715782 2023-03-27T22:47:53 Z Ahmed57 Olympiads (BOI19_olympiads) C++14
100 / 100
54 ms 10760 KB
#include <bits/stdc++.h>

using namespace std;
int k,n;
int p[501][7];
struct Partition{
    vector<int> best,choice;
    long long cost;
    Partition(vector<int> A):choice(A){
        vector<int> tmp(k,0);
        int cnt = 0;
        for(int i = 0;i<n;i++){
            if(choice[i]==1){
                cnt++;
                best.push_back(i);
                for(int j = 0;j<k;j++){
                    tmp[j] = max(tmp[j],p[i][j]);
                }
            }
        }
        vector<int> tt = choice;
        if(cnt>k){
            cost = INT_MIN;
            return ;
        }
        while(cnt<k){
            int mx = -1 , id = 0;
            for(int i = 0;i<n;i++){
                if(tt[i]==0&&mx<p[i][cnt]){
                    mx = p[i][cnt];
                    id = i;
                }
            }
            if(mx==-1){
                cost = INT_MIN;
                return ;
            }
            tt[id] = 1;
            best.push_back(id);
            for(int i = 0;i<k;i++){
                tmp[i] = max(tmp[i],p[id][i]);
            }
            cnt++;
        }
        cost = accumulate(tmp.begin(),tmp.end(),0);
    }
    bool operator <(Partition r) const{
		return cost < r.cost;
	}
};
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int c;cin>>n>>k>>c;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<k;j++){
            cin>>p[i][j];
        }
    }
    priority_queue<Partition> q;
    q.push(Partition(vector<int>(n, 0)));
    /*
    5 4 4
    7 0 4 9
    3 0 8 4
    1 1 3 7
    5 1 3 4
    4 2 2 9
    */
    while(c--){
        auto w = q.top();q.pop();
        if(c==0){
            cout<<w.cost<<"\n";
            return 0;
        }
        for(int i = 0;i<k;i++){
            if(w.choice[w.best[i]]==0){
                vector<int> choice = w.choice;
                choice[w.best[i]] = -1;
                for(int j = 0;j<i;j++){
                    choice[w.best[j]] = 1;
                }
                q.push(Partition(choice));
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 340 KB Output is correct
2 Correct 9 ms 468 KB Output is correct
3 Correct 8 ms 340 KB Output is correct
4 Correct 6 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 596 KB Output is correct
2 Correct 4 ms 328 KB Output is correct
3 Correct 7 ms 972 KB Output is correct
4 Correct 6 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 468 KB Output is correct
2 Correct 9 ms 396 KB Output is correct
3 Correct 30 ms 6904 KB Output is correct
4 Correct 33 ms 6532 KB Output is correct
5 Correct 16 ms 2316 KB Output is correct
6 Correct 5 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 340 KB Output is correct
2 Correct 9 ms 468 KB Output is correct
3 Correct 8 ms 340 KB Output is correct
4 Correct 6 ms 364 KB Output is correct
5 Correct 6 ms 596 KB Output is correct
6 Correct 4 ms 328 KB Output is correct
7 Correct 7 ms 972 KB Output is correct
8 Correct 6 ms 712 KB Output is correct
9 Correct 11 ms 468 KB Output is correct
10 Correct 9 ms 396 KB Output is correct
11 Correct 30 ms 6904 KB Output is correct
12 Correct 33 ms 6532 KB Output is correct
13 Correct 16 ms 2316 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 14 ms 1620 KB Output is correct
16 Correct 31 ms 5008 KB Output is correct
17 Correct 54 ms 10760 KB Output is correct
18 Correct 23 ms 4472 KB Output is correct
19 Correct 8 ms 340 KB Output is correct