#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vc = vector<char>;
using vvc = vector<vc>;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
void setIO()
{
fast;
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
}
int main()
{
setIO();
int n,m,k;
cin>>n>>m>>k;
vvl scores(n,vl(m));
for (int i = 0;i<n;i++)for (int j = 0;j<m;j++)cin>>scores[i][j];
vvi best_scores(m,vi(n));
for (int i = 0;i<m;i++){
for (int j = 0;j<n;j++)best_scores[i][j] = j;
sort(best_scores[i].begin(), best_scores[i].end(),[&](int a,int b){
return scores[a][i] > scores[b][i];
});
}
struct Item{
int score;
int pos;
vi current;
vb forbidden;
const bool operator<(const Item &other)const{
return score < other.score;
}
};
const auto evaluate = [&](const vi& cur)
{
vl res(m);
ll ret = 0;
for (int i = 0;i<(int)cur.size();i++){
int pos = best_scores[i][cur[i]];
for (int j = 0;j<m;j++){
res[j] = max(res[j],scores[pos][j]);
}
}
for (int j = 0;j<m;j++)ret += res[j];
return ret;
};
Item best;
best.score = 0,best.pos = 0;
best.current.assign(m,-1);
best.forbidden.assign(n,0);
for (int i = 0;i<m;i++){
int pos = 0;
while (pos < n && best.forbidden[best_scores[i][pos]])pos++;
if (pos < n){
best.current[i] = pos;
best.forbidden[best_scores[i][pos]] = 1;
}
}
best.score = evaluate(best.current);
k--;
priority_queue<Item>pq;
pq.push(best);
while (k--){
Item now = pq.top();
pq.pop();
for (int j = now.pos;j<m;j++){
int pos = now.current[j];
now.forbidden[best_scores[j][now.current[j]]] = 1;
while (pos < n && now.forbidden[best_scores[j][pos]])pos++;
if (pos < n){
Item next = now;
next.pos = j;
next.current[j] = pos;
next.score = evaluate(next.current);
next.forbidden[best_scores[j][pos]] = 1;
pq.push(next);
}
}
}
cout<<pq.top().score;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
360 KB |
Output is correct |
2 |
Correct |
4 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
352 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
5 ms |
716 KB |
Output is correct |
3 |
Correct |
4 ms |
716 KB |
Output is correct |
4 |
Correct |
5 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
952 KB |
Output is correct |
4 |
Correct |
6 ms |
844 KB |
Output is correct |
5 |
Correct |
7 ms |
1336 KB |
Output is correct |
6 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
360 KB |
Output is correct |
2 |
Correct |
4 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
352 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
716 KB |
Output is correct |
7 |
Correct |
4 ms |
716 KB |
Output is correct |
8 |
Correct |
5 ms |
588 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
6 ms |
952 KB |
Output is correct |
12 |
Correct |
6 ms |
844 KB |
Output is correct |
13 |
Correct |
7 ms |
1336 KB |
Output is correct |
14 |
Correct |
4 ms |
716 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
7 ms |
1104 KB |
Output is correct |
17 |
Correct |
8 ms |
1336 KB |
Output is correct |
18 |
Correct |
5 ms |
716 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |