#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
void open_file(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 505;
const int maxV = 6 * 1e3 + 25;
struct node {
vector<int> B; int val;
};
bool used[maxN];
deque<node> dq[maxV];
int n, k, c, arr[maxN][10];
node getmax() {
int sum = 0;
vector<int> vec;
bool used_[n + 1] = {};
for (int i = 1; i <= k; i++) {
int mx = -inf, pos;
for (int j = 1; j <= n; j++) {
if (used[j]) continue;
if (mx < arr[j][i]) {
mx = arr[j][i]; pos = j;
}
} sum += mx;
if (used_[pos]) {
for (int j = 1; j <= n; j++) {
if (used[j] == 0 && used_[j] == 0) {
pos = j; break;
}
}
} if (used_[pos]) return {{}, 0};
vec.pb(pos); used_[pos] = 1;
} return {vec, sum};
}
void solve() {
cin >> n >> k >> c;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= k; j++)
cin >> arr[i][j];
set<pair<int, pair<vector<int>, int>>> st;
st.insert({getmax().val, {{}, 0}});
int A_A_A;
while (c--) {
pair<int, pair<vector<int>, int>> curr = *st.rbegin();
A_A_A = curr.ff;
st.erase(--st.end());
int pos = curr.sc.sc;
vector<int> v = curr.sc.ff;
for (int x : v) used[x] = 1;
vector<int> cur = getmax().B;
for (int i = pos; i < k; i++) {
used[cur[i]] = 1;
vector<int> tmp = v;
tmp.pb(cur[i]);
st.insert({getmax().val, {tmp, i}});
used[cur[i]] = 0;
} for (int x : v) used[x] = 0;
} cout << A_A_A;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
Compilation message
olympiads.cpp: In function 'void open_file(std::string)':
olympiads.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen((filename + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen((filename + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp: In function 'node getmax()':
olympiads.cpp:56:22: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
56 | if (used_[pos]) {
| ~~~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4700 KB |
Output is correct |
2 |
Correct |
7 ms |
4604 KB |
Output is correct |
3 |
Correct |
7 ms |
4700 KB |
Output is correct |
4 |
Correct |
7 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4700 KB |
Output is correct |
2 |
Correct |
4 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
4956 KB |
Output is correct |
4 |
Correct |
5 ms |
4784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
4700 KB |
Output is correct |
2 |
Correct |
16 ms |
4568 KB |
Output is correct |
3 |
Correct |
33 ms |
7368 KB |
Output is correct |
4 |
Correct |
31 ms |
7324 KB |
Output is correct |
5 |
Correct |
21 ms |
4956 KB |
Output is correct |
6 |
Correct |
5 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4700 KB |
Output is correct |
2 |
Correct |
7 ms |
4604 KB |
Output is correct |
3 |
Correct |
7 ms |
4700 KB |
Output is correct |
4 |
Correct |
7 ms |
4700 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
4 ms |
4444 KB |
Output is correct |
7 |
Correct |
5 ms |
4956 KB |
Output is correct |
8 |
Correct |
5 ms |
4784 KB |
Output is correct |
9 |
Correct |
18 ms |
4700 KB |
Output is correct |
10 |
Correct |
16 ms |
4568 KB |
Output is correct |
11 |
Correct |
33 ms |
7368 KB |
Output is correct |
12 |
Correct |
31 ms |
7324 KB |
Output is correct |
13 |
Correct |
21 ms |
4956 KB |
Output is correct |
14 |
Correct |
5 ms |
4700 KB |
Output is correct |
15 |
Correct |
17 ms |
4828 KB |
Output is correct |
16 |
Correct |
23 ms |
5468 KB |
Output is correct |
17 |
Correct |
45 ms |
12348 KB |
Output is correct |
18 |
Correct |
23 ms |
5468 KB |
Output is correct |
19 |
Correct |
14 ms |
4700 KB |
Output is correct |