// author : sentheta aka vanwij
#ifdef VANWIJ
#include"/home/user/code/bits/stdc++.h"
#define DBG 1
#else
#include"bits/stdc++.h"
#define DBG 0
#endif
using namespace std;
#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second
static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))
#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define cerr if(DBG) cout
#define dbg(x) {cerr << "?" << #x << " : " << (x) << endl << flush;}
#define int long long
// const Int MOD = 1e9+7;
const Int MOD = 998244353;
Int bpow(Int a,Int b){
Int ret = 1;
for(;b; a=a*a%MOD,b/=2) if(b&1) ret = ret*a%MOD;
return ret;
}
Int inv(Int a){return bpow(a,MOD-2);}
void solve(); int TC, ALLTC;
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(7);
// cin >> ALLTC; for(TC=1; TC<=ALLTC; TC++) solve(); return 0;
solve();
}
const int N = 512;
const int K = 6;
#define Array array<int,6>
#define Bitset bitset<N>
Array empMembers, empScores={-1,-1,-1,-1,-1,-1};
int n, k, c;
// {score, event, player}
V<array<int,3>> v;
int vis[N], t;
// fix = #elems in prefix that cannot be changed
struct Team{
int sum, fix;
Array members;
Bitset ban;
bool operator<(const Team& o)const{
return sum < o.sum;
}
};
void solve(){
cin >> n >> k >> c;
rep(i,1,n+1) rep(j,0,k){
int x;
cin >> x;
v.push_back({x, j, i});
}
sort(all(v));
reverse(all(v));
// for(auto[x,j,i] : v) cerr << x _ j _ i << nl;
priority_queue<Team> pq;
{
t++;
int sz = 0;
Array members=empMembers, scores=empScores;
// main players
for(auto[x,j,i] : v) if(sz<k && x>scores[j]){
scores[j] = x;
if(vis[i]!=t){
vis[i] = t;
members[sz++] = i;
if(sz==k) break;
}
}
// extra players
for(auto[x,j,i] : v) if(sz<k){
if(vis[i]!=t){
vis[i] = t;
members[sz++] = i;
if(sz==k) break;
}
}
int sum = 0;
rep(j,0,k){
dbg(scores[j]);
sum += scores[j];
}
dbg(sum);
for(int i : members) cerr << i << " ";
cerr << nl;
pq.push({
sum, 0, members, Bitset()
});
}
rep(loop,0,c-1){
Team team = pq.top(); pq.pop();
dbg(team.sum);
int fix = team.fix;
for(; fix<k; fix++){
Bitset ban = team.ban;
ban[team.members[fix]] = 1;
t++;
int sz = 0;
Array members=empMembers, scores=empScores;
// main players
for(auto[x,j,i] : v) if(!ban[i] && sz<k && x>scores[j]){
scores[j] = x;
if(vis[i]!=t){
vis[i] = t;
members[sz++] = i;
if(sz==k) break;
}
}
// extra players
for(auto[x,j,i] : v) if(!ban[i] && sz<k){
if(vis[i]!=t){
vis[i] = t;
members[sz++] = i;
if(sz==k) break;
}
}
if(sz!=k) continue;
int nwSum = 0;
rep(j,0,k){
nwSum += scores[j];
}
// dbg(nwSum);
// for(int i : members) cerr << i << " ";
// cerr << nl;
pq.push({
nwSum, fix, members, ban
});
}
}
int ans = pq.top().sum;
cout << ans << nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
328 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
468 KB |
Output is correct |
2 |
Correct |
8 ms |
468 KB |
Output is correct |
3 |
Correct |
12 ms |
468 KB |
Output is correct |
4 |
Correct |
13 ms |
468 KB |
Output is correct |
5 |
Correct |
12 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
328 KB |
Output is correct |
9 |
Correct |
11 ms |
468 KB |
Output is correct |
10 |
Correct |
8 ms |
468 KB |
Output is correct |
11 |
Correct |
12 ms |
468 KB |
Output is correct |
12 |
Correct |
13 ms |
468 KB |
Output is correct |
13 |
Correct |
12 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
596 KB |
Output is correct |
16 |
Correct |
29 ms |
1104 KB |
Output is correct |
17 |
Correct |
28 ms |
468 KB |
Output is correct |
18 |
Correct |
11 ms |
484 KB |
Output is correct |
19 |
Correct |
9 ms |
484 KB |
Output is correct |