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;
typedef long long ll;
#define F first
#define S second
#define pb push_back
//#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 507;
const ll inf = 1e9;
const ll mod = 998244353;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
bool cmp(int a, int b) { return (a > b); }
int n, k, c, a[M][M];
bool valid (vector <int> v, int person) {
for(auto i : v) if(person == i) return 0;
return 1;
}
int val (vector <int> v) {
int ret = 0;
for(int i = 1; i <= (int)v.size(); ++i){
int mx = 0;
for(auto j : v) mx = max(mx, a[-j][i]);
ret += mx;
}
return ret;
}
int main()
{
scanf("%d%d%d", &n, &k, &c);
for(int i = 1; i <= n; ++i) for(int j = 1; j <= k; ++j) scanf("%d", &a[i][j]);
vector < pair < int, vector <int> > > v;
v.pb({0, {}});
for(int turn = 1; turn <= k; ++turn){
vector < pair < int, vector <int> > > to;
for(auto i : v){
for(int j = 1; j <= n; ++j) if(valid(i.S, -j)) {
vector <int> tmp = i.S; tmp.pb(-j);
sort(all(tmp), cmp);
to.pb({-val(tmp), tmp});
}
}
v.clear();
for(auto i : to){
bool add = 1;
for(auto j : v) if(i.S == j.S){
add = 0;
break;
}
if(add) v.pb(i);
}
sort(all(v));
while((int)v.size() > 2 * c) v.pop_back();
//for(auto i : v){
//cout << i.F << " " ;
//for(auto j : i.S) cout << j << " ";
//cout << endl;
//}
}
printf("%d\n", -v.back().F);
return 0;
}
Compilation message (stderr)
olympiads.cpp: In function 'int main()':
olympiads.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d%d", &n, &k, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:37:63: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | for(int i = 1; i <= n; ++i) for(int j = 1; j <= k; ++j) scanf("%d", &a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
# | 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... |