#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
using namespace std;
mt19937_64 rng(228);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
bool umn(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
int n, k, c;
int a[505][7];
ve<int> st;
int mx[7];
ve<int> scores;
int sum[505];
ve<int> order;
void rec(int p = 1) {
if (sz(st) == k) {
fr (i, 1, k) mx[i] = -1e9;
fe (cur, st) {
fr (i, 1, k) {
umx(mx[i], a[cur][i]);
}
}
int sum = 0;
fr (i, 1, k) sum += mx[i];
scores.pb(sum);
return;
}
if (p > n) return;
rec(p + 1);
st.pb(p);
rec(p + 1);
st.pop_back();
}
int need[7];
int mask[505];
ll dp[7][64];
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios::sync_with_stdio(0);
cin.tie(0);
#endif
ve<array<int, 6>> res;
fr (a1, 0, 10) {
fr (a2, 0, 10) {
fr (a3, 0, 10) {
fr (a4, 0, 10) {
fr (a5, 0, 10) {
fr (a6, 0, 10) {
if (a1 + a2 + a3 + a4 + a5 + a6 <= 10) {
res.pb({a1, a2, a3, a4, a5, a6});
}
}
}
}
}
}
}
// cout << cnt << "\n";
//
// return 0;
cin >> n >> k >> c;
fr (i, 1, n) {
fr (j, 1, k) {
cin >> a[i][j];
}
}
if (n > 40 && k > 2) {
fe (cur, res) {
fr (i, k, 5) {
cur[i] = 0;
}
}
sort(all(res));
res.erase(unique(all(res)), res.end());
sort(all(res), [](array<int, 6> a, array<int, 6> b) {
int sum1 = 0;
fr (i, 0, k - 1) sum1 += a[i];
int sum2 = 0;
fr (i, 0, k - 1) sum2 += b[i];
return sum1 > sum2;
});
// map<pii, int> occ;
// fr (i ,1, n) {
// fr (j, i + 1, n) {
// occ[{max(a[i][1], a[j][1]), max(a[i][2], a[j][2])}]++;
// }
// }
//
// fe (cur, occ) {
// if (cur.fi.fi + cur.fi.se <= 10) {
// cout << cur.fi.fi << " " << cur.fi.se << " " << cur.se << "\n";
// }
// }
fr (j, 0, sz(res) - 1) {
fr (i, 1, k) {
need[i] = res[j][i - 1];
}
ve<int> have;
fr (i, 1, n) {
bool bad = 0;
fr (j, 1, k) {
if (a[i][j] > need[j]) {
bad = 1;
break;
}
}
if (!bad) {
int mask = 0;
fr (j, 1, k) {
if (a[i][j] == need[j]) {
mask |= pw(j - 1);
}
}
have.pb(mask);
}
}
fr (mask, 0, 63) {
fr (take, 0, k) {
dp[take][mask] = 0;
}
}
dp[0][0] = 1;
fe (cur, have) {
rf (was, k - 1, 0) {
fr (mask, 0, pw(k) - 1) {
dp[was + 1][mask | cur] += dp[was][mask];
umn(dp[was + 1][mask | cur], 1001LL);
}
}
}
c -= dp[k][pw(k) - 1];
if (c <= 0) {
int sum = 0;
fr (i, 1, k) sum += need[i];
cout << sum << "\n";
return 0;
}
}
// assert(0);
return 0;
}
rec();
sort(all(scores));
reverse(all(scores));
cout << scores[c - 1] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1168 KB |
Output is correct |
2 |
Correct |
11 ms |
1168 KB |
Output is correct |
3 |
Correct |
9 ms |
1168 KB |
Output is correct |
4 |
Correct |
5 ms |
1168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
526 ms |
17024 KB |
Output is correct |
2 |
Correct |
507 ms |
16988 KB |
Output is correct |
3 |
Correct |
560 ms |
17000 KB |
Output is correct |
4 |
Correct |
527 ms |
17024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1168 KB |
Output is correct |
2 |
Correct |
11 ms |
1168 KB |
Output is correct |
3 |
Correct |
9 ms |
1168 KB |
Output is correct |
4 |
Correct |
5 ms |
1168 KB |
Output is correct |
5 |
Correct |
526 ms |
17024 KB |
Output is correct |
6 |
Correct |
507 ms |
16988 KB |
Output is correct |
7 |
Correct |
560 ms |
17000 KB |
Output is correct |
8 |
Correct |
527 ms |
17024 KB |
Output is correct |
9 |
Incorrect |
17 ms |
660 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |