Submission #1077375

# Submission time Handle Problem Language Result Execution time Memory
1077375 2024-08-27T06:21:33 Z duckindog Olympiads (BOI19_olympiads) C++17
100 / 100
31 ms 7212 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 10;
int n, k, c;
int a[N][10];

int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);

  cin >> n >> k >> c;
  for (int i = 0; i < n; ++i) { 
    for (int j = 0; j < k; ++j) cin >> a[i][j];
  }

  auto sort = [&](vector<int> &v) {
    for (int i = 0; i < k; ++i) {
      for (int j = i + 1; j < v.size(); ++j)
        if (a[v[j]][i] > a[v[i]][i]) swap(v[i], v[j]);
    }
  };
  auto cal = [&](vector<int> &v) { 
    long long ret = 0;
    for (int i = 0; i < k; ++i) { 
      int ma = 0;
      for (const auto& j : v) ma = max(ma, a[j][i]);
      ret += ma;
    }
    return ret;
  };

  priority_queue<tuple<long long, int, vector<int>>> q;
  { //init
    vector<int> vt(n); iota(vt.begin(), vt.end(), 0);
    sort(vt);
    q.emplace(cal(vt), 0, vt);
  }

  while (q.size()) { 
    auto [value, p, vt] = q.top(); q.pop();
    if (!--c) { cout << value << "\n"; return 0; }
    if (vt.size() == k) continue;
    for (int i = p; i < k; ++i) { 
      vector<int> nxt = vt;
      nxt.erase(nxt.begin() + i);
      sort(nxt);
      q.emplace(cal(nxt), i, nxt);
    }
  }
}

Compilation message

olympiads.cpp: In lambda function:
olympiads.cpp:19:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |       for (int j = i + 1; j < v.size(); ++j)
      |                           ~~^~~~~~~~~~
olympiads.cpp: In function 'int32_t main()':
olympiads.cpp:43:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |     if (vt.size() == k) continue;
      |         ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 6 ms 600 KB Output is correct
3 Correct 7 ms 496 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 464 KB Output is correct
2 Correct 7 ms 600 KB Output is correct
3 Correct 28 ms 4948 KB Output is correct
4 Correct 24 ms 4600 KB Output is correct
5 Correct 10 ms 1116 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 6 ms 600 KB Output is correct
3 Correct 7 ms 496 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 9 ms 464 KB Output is correct
10 Correct 7 ms 600 KB Output is correct
11 Correct 28 ms 4948 KB Output is correct
12 Correct 24 ms 4600 KB Output is correct
13 Correct 10 ms 1116 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 16 ms 1628 KB Output is correct
16 Correct 29 ms 4444 KB Output is correct
17 Correct 31 ms 7212 KB Output is correct
18 Correct 28 ms 4104 KB Output is correct
19 Correct 7 ms 604 KB Output is correct