Submission #1217086

#TimeUsernameProblemLanguageResultExecution timeMemory
1217086badge881Olympiads (BOI19_olympiads)C++20
100 / 100
37 ms20580 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100, M = 1e5 + 10, K = 52, MX = 30; int n, k, c; array<int, 6> a[N]; struct Partition { vector<pair<int, int>> ban; int fix, cost; vector<int> span; private: int val(vector<int> &v) { int cost = 0; for (int i = 0; i < k; ++i) { int x = 0; for (int j : v) x = max(x, a[j][i]); cost += x; } return cost; } public: Partition(vector<pair<int, int>> t, int fx) : fix(fx), ban(t) { cost = 0; for (int i = 0; i < k; ++i) { bool nice = 0; int best = 0; for (int j = 1; j <= n; ++j) if (ban[j].first == 1 && ban[j].second == i) { nice = 1; span.push_back(j); break; } else if (ban[j].first == 0) best = best == 0 ? j : (a[j][i] > a[best][i] ? j : best); if (!nice) { if (best == 0) break; span.push_back(best); ban[best] = {1, i}; } } cost = val(span); } bool operator<(const Partition &other) const { return cost < other.cost; } }; signed main() { scanf("%d%d%d", &n, &k, &c); for (int i = 1; i <= n; ++i) for (int j = 0; j < k; ++j) scanf("%d", &a[i][j]); priority_queue<Partition> Q; vector<pair<int, int>> T(n + 1); Partition X(T, 0); Q.push(X); while (c--) { auto cur = Q.top(); Q.pop(); if (c == 0) { printf("%d\n", cur.cost); return 0; } for (int j = cur.fix; j < k; ++j) { vector<pair<int, int>> T = cur.ban; T[cur.span[j]].first = 2; Partition p(T, j); if (p.span.size() == k) Q.push(p); } } }

Compilation message (stderr)

olympiads.cpp: In function 'int main()':
olympiads.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d%d%d", &n, &k, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:67:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |             scanf("%d", &a[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...