# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863096 | Benmath | Olympiads (BOI19_olympiads) | C++14 | 842 ms | 19380 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std; int niz[41][7];
int n, k , c;
int solve(vector<int>indeksi){
int maxi[k];
for(int i = 0; i < k; i++){
maxi[i] = 0;
}
for(int i = 0; i < indeksi.size(); i++){
int tren = indeksi[i];
for(int j = 0; j < k; j++){
maxi[j] = max(maxi[j], niz[tren][j]);
}
}
int sum = 0;
for(int i = 0; i < k; i++){
sum = sum + maxi[i];
}
return sum;
}
int main(){
cin >> n >> k >> c;
for(int i = 0; i < n; i++){
for(int j = 0; j < k; j++){
cin >> niz[i][j];
}
}
int so = n / 2;
vector<int>vector1[n + 1];
vector<int>vector2[n + 1];
for(int i = 0; i < so; i ++){
for(int j = 0; j < k; j++){
vector1[i].push_back(niz[i][j]);
}
}
for(int i = so; i < n; i++){
for(int j = 0; j < k; j++){
vector2[i - so].push_back(niz[i][j]);
}
}
int size1 = so;
int size2 = n - so;
vector<int>v1[k + 1];
vector<int>v2[k + 1];
vector<int>ans;
for(int i = 0; i < (1<<size1); i++){ int brojac = 0;
for(int j = 0; j < size1; j++){
int res = i & (1<<j);
if(res != 0){
brojac++;
}
}
if(brojac <= k){
v1[brojac].push_back(i);
}
}
for(int i = 0; i < (1<<size2); i++){ int brojac = 0;
for(int j = 0; j < size2; j++){
int res = i & (1<<j);
if(res != 0){
brojac++;
}
}
if(brojac <= k){
v2[brojac].push_back(i);
}
}
for(int i = 0; i <= k; i++){
int velicina = v1[i].size();
for(int j = 0; j < velicina; j ++){
vector<int>prvi_indeksi;
int x = v1[i][j];
for(int j1 = 0; j1 < size1; j1++){
int res = x & (1<<j1);
if(res != 0){
prvi_indeksi.push_back(j1);
}
}
int velicina2 = v2[k - i].size();
for(int t = 0; t < velicina2; t++){
vector<int>indeksi = prvi_indeksi;
int x = v2[k - i][t];
for(int j1 = 0; j1 < size2; j1++){
int res = x & (1<<j1);
if(res != 0){
indeksi.push_back(j1 + so);
}
}
ans.push_back(solve(indeksi));
}
}
}
sort(ans.begin(),ans.end());
int to = ans.size();
cout << ans[to - c];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |