#include <map>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, K, C;
cin >> N >> K >> C;
vector<vector<int> > A(N, vector<int>(K));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < K; ++j) {
cin >> A[i][j];
}
}
vector<vector<int> > perm(K, vector<int>(N));
for (int i = 0; i < K; ++i) {
for (int j = 0; j < N; ++j) {
perm[i][j] = j;
}
sort(perm[i].begin(), perm[i].end(), [&](int j, int k) { return A[j][i] != A[k][i] ? A[j][i] > A[k][i] : j < k; });
}
map<vector<int>, bool> vis;
priority_queue<pair<int, vector<int> > > que;
int maxsum = 0;
for (int i = 0; i < K; ++i) {
maxsum += A[perm[i][0]][i];
}
que.push(make_pair(maxsum, vector<int>(K, 0)));
long long cnt = 0;
while (!que.empty()) {
pair<int, vector<int> > bs = que.top(); que.pop();
int score = bs.first;
vector<int> v = bs.second;
vector<bool> ban(N, false);
vector<int> id(K);
for (int i = 0; i < K; ++i) {
id[i] = perm[i][v[i]];
for (int j = 0; j < v[i]; ++j) {
ban[perm[i][j]] = true;
}
}
bool valid = true;
for (int i = 0; i < K; ++i) {
if (ban[id[i]]) valid = false;
}
if (valid) {
sort(id.begin(), id.end());
id.erase(unique(id.begin(), id.end()), id.end());
int sel = -int(id.size());
for (int i = 0; i < N; ++i) {
if (!ban[i]) ++sel;
}
long long mul = 1;
for (int i = 1; i <= K - id.size(); ++i) {
mul *= sel - i + 1;
mul /= i;
}
cnt += mul;
if (cnt >= C) {
cout << score << endl;
break;
}
}
for (int i = 0; i < K; ++i) {
if (v[i] == N - 1) continue;
vector<int> vnxt = v;
++vnxt[i];
if (vis[vnxt]) continue;
int nxtscore = 0;
for (int j = 0; j < K; ++j) {
nxtscore += A[perm[j][vnxt[j]]][j];
}
vis[vnxt] = true;
que.push(make_pair(nxtscore, vnxt));
}
}
return 0;
}
Compilation message
olympiads.cpp: In function 'int main()':
olympiads.cpp:57:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i <= K - id.size(); ++i) {
~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
508 KB |
Output is correct |
4 |
Correct |
104 ms |
3584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
7 ms |
1276 KB |
Output is correct |
3 |
Correct |
9 ms |
1524 KB |
Output is correct |
4 |
Correct |
9 ms |
1396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
13 ms |
1908 KB |
Output is correct |
4 |
Correct |
14 ms |
2296 KB |
Output is correct |
5 |
Correct |
13 ms |
2060 KB |
Output is correct |
6 |
Correct |
27 ms |
4204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
508 KB |
Output is correct |
4 |
Correct |
104 ms |
3584 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
7 ms |
1276 KB |
Output is correct |
7 |
Correct |
9 ms |
1524 KB |
Output is correct |
8 |
Correct |
9 ms |
1396 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
13 ms |
1908 KB |
Output is correct |
12 |
Correct |
14 ms |
2296 KB |
Output is correct |
13 |
Correct |
13 ms |
2060 KB |
Output is correct |
14 |
Correct |
27 ms |
4204 KB |
Output is correct |
15 |
Correct |
12 ms |
1272 KB |
Output is correct |
16 |
Correct |
6 ms |
888 KB |
Output is correct |
17 |
Correct |
16 ms |
2292 KB |
Output is correct |
18 |
Correct |
14 ms |
2036 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |