#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500;
const int MAX_K = 6;
struct team {
int total;
int score[MAX_K];
void init() {
total = 0;
for ( int i = 0; i < MAX_K; i++ )
score[i] = 0;
}
bool operator < ( const team &t ) const {
return total < t.total;
}
team operator + ( const team &t ) const {
team ans;
ans.total = 0;
for ( int i = 0; i < MAX_K; i++ ) {
ans.score[i] = max( score[i], t.score[i] );
ans.total += ans.score[i];
}
return ans;
}
};
team students[MAX_N + 1];
int maxScore[MAX_N + 2][1 << MAX_K];
int n, k, m, cnt;
void bckt( int c, int s, int p, team crt ) {
if ( cnt >= m )
return;
if ( c > n - p )
return;
int maxS = 0;
for ( int mask = 0; mask < (1 << k); mask++ ) {
int score = 0;
for ( int j = 0; j < k; j++ ) {
if ( (mask >> j) & 1 )
continue;
score += crt.score[j];
}
maxS = max( maxS, score + maxScore[p + 1][mask] );
}
if ( maxS < s )
return;
if ( c == 0 ) {
if ( crt.total >= s )
cnt++;
return;
}
for ( int i = p + 1; i <= n; i++ ) {
bckt( c - 1, s, i, crt + students[i] );
}
}
int main() {
cin >> n >> k >> m;
for ( int i = 1; i <= n; i++ ) {
for ( int j = 0; j < k; j++ ) {
cin >> students[i].score[j];
students[i].total += students[i].score[j];
}
}
for ( int i = n; i >= 1; i-- ) {
for ( int maskPrv = 0; maskPrv < (1 << k); maskPrv++ ) {
for ( int mask = 0; mask < (1 << k); mask++ ) {
if ( (maskPrv & mask) > 0 )
continue;
int s = 0;
for ( int j = 0; j < k; j++ ) {
if ( (mask >> j) & 1 )
s += students[i].score[j];
}
int maskCrt = (maskPrv | mask);
maxScore[i][maskCrt] = max( maxScore[i][maskCrt], maxScore[i + 1][maskPrv] + s );
}
}
}
int st = 0, dr = maxScore[1][(1 << k) - 1] + 1;
while ( dr - st > 1 ) {
int mij = (st + dr) / 2;
cnt = 0;
team crt;
crt.init();
bckt( k, mij, 0, crt );
if ( cnt < m )
dr = mij;
else
st = mij;
}
cout << st;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
344 KB |
Output is correct |
2 |
Correct |
14 ms |
564 KB |
Output is correct |
3 |
Correct |
7 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2027 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1673 ms |
544 KB |
Output is correct |
2 |
Correct |
10 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2009 ms |
344 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
344 KB |
Output is correct |
2 |
Correct |
14 ms |
564 KB |
Output is correct |
3 |
Correct |
7 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Execution timed out |
2027 ms |
344 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |