Submission #688533

#TimeUsernameProblemLanguageResultExecution timeMemory
688533stanislavpolynOlympiads (BOI19_olympiads)C++17
44 / 100
638 ms85088 KiB
#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 totMx[7]; int rnd(int l, int r) { return rng() % (r - l + 1) + l; } 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}); // } } } } } } } cin >> n >> k >> c; int wasC = c; fr (i, 1, n) { fr (j, 1, k) { cin >> a[i][j]; // a[i][j] = rnd(0, 10); umx(totMx[j], a[i][j]); } } bool subtask = 1; fr (i, 1, k) { subtask &= totMx[i] <= 10; } if (subtask) { assert(0); // assert(sum <= 10); 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"; // } // } bool found = 0; 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); } } if (sz(have)) { 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); } } } // if (dp[k][pw(k) - 1]) { // cout << need[1] << " " << need[2] << " " << dp[k][pw(k) - 1] << "\n"; // } c -= dp[k][pw(k) - 1]; if (c <= 0) { int sum = 0; fr (i, 1, k) sum += need[i]; cout << sum << "\n"; // return 0; found = 1; break; } } } assert(found); return 0; } rec(); // cout << sz(scores) << "\n"; // fe (cur, scores) cout << cur << " "; // cout << "\n"; c = wasC; // sort(all(scores)); reverse(all(scores)); cerr << sz(scores) << "\n"; cout << scores[c - 1] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...