#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 1e5 + 5;
const int INF = 1e9 + 7;
int a[505][10];
int n, k, c;
struct info{
set<int> idx;
int ans;
info(){}
info(set<int> _idx, int _ans) : idx(_idx), ans(_ans){}
bool operator < (const info& other) const{
return ans < other.ans;
}
};
set<set<int>> used;
int cal(set<int> id){
vector<int> mx(k);
for(auto x : id){
for(int i = 0; i < k; i++){
mx[i] = max(mx[i], a[x][i]);
}
}
return accumulate(mx.begin(), mx.end(), 0);
}
signed main(void){
fastio;
cin>>n>>k>>c;
vector<int> mx(k);
for(int i = 0; i < n; i++){
for(int j = 0; j < k; j++){
cin>>a[i][j];
if(a[i][j] > a[mx[j]][j]) mx[j] = i;
}
}
set<int> st;
for(int i = 0; i < k; i++) st.insert(mx[i]);
for(int i = 0; i < n; i++){
if(st.size() == k) break;
if(st.count(i)) continue;
st.insert(i);
}
used.insert(st);
priority_queue<info> q;
q.push(info(st, cal(st)));
for(int rd = 0; rd < c; rd++){
auto [idx, ans] = q.top(); q.pop();
if(rd == c - 1){
cout<<ans<<"\n";
return 0;
}
for(auto x : idx){
set<int> cur;
for(auto u : idx){
if(u != x) cur.insert(u);
}
for(int j = 0; j < n; j++){
if(!cur.count(j)){
cur.insert(j);
if(!used.count(cur)){
q.push(info(cur, cal(cur)));
used.insert(cur);
}
cur.erase(j);
}
}
}
}
}
Compilation message
olympiads.cpp: In function 'int main()':
olympiads.cpp:51:22: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
51 | if(st.size() == k) break;
| ~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
594 ms |
42380 KB |
Output is correct |
2 |
Correct |
580 ms |
42268 KB |
Output is correct |
3 |
Correct |
621 ms |
42316 KB |
Output is correct |
4 |
Correct |
525 ms |
42252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
512 ms |
66744 KB |
Output is correct |
2 |
Correct |
494 ms |
54964 KB |
Output is correct |
3 |
Correct |
510 ms |
61468 KB |
Output is correct |
4 |
Correct |
460 ms |
56348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
909 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
594 ms |
42380 KB |
Output is correct |
2 |
Correct |
580 ms |
42268 KB |
Output is correct |
3 |
Correct |
621 ms |
42316 KB |
Output is correct |
4 |
Correct |
525 ms |
42252 KB |
Output is correct |
5 |
Correct |
512 ms |
66744 KB |
Output is correct |
6 |
Correct |
494 ms |
54964 KB |
Output is correct |
7 |
Correct |
510 ms |
61468 KB |
Output is correct |
8 |
Correct |
460 ms |
56348 KB |
Output is correct |
9 |
Runtime error |
909 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |