Submission #824220

# Submission time Handle Problem Language Result Execution time Memory
824220 2023-08-13T19:07:51 Z tch1cherin Olympiads (BOI19_olympiads) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 500, MAX_K = 6;
int score[MAX_N][MAX_K];
int N, K, C;

struct Node {
  bitset<MAX_N> is_forbidden, used;
  int count_forced;
  int best[MAX_K];
  int value;

  Node() {
    count_forced = 0;
    eval();
  }

  Node(Node* parent, int _count_forced) {
    is_forbidden = parent->is_forbidden;
    count_forced = _count_forced;
    for (int i = 0; i < count_forced; i++) {
      best[i] = parent->best[i];
      used[best[i]] = true;
    }
    is_forbidden[parent->best[count_forced]] = true;
    eval();
  }

  void eval() {
    for (int event = count_forced; event < K; event++) {
      best[event] = -1;
      for (int i = 0; i < N; i++) {
        if (!is_forbidden[i] && !used[i] && (best[event] == -1 || score[i][event] > score[best[event]][event])) {
          best[event] = i;
        }
      }
      if (best[event] == -1) {
        value = INT_MIN;
        return;
      }
      used[best[event]] = true;
    }
    value = 0;
    for (int event = 0; event < K; event++) {
      int max_score = 0;
      for (int i = 0; i < K; i++) {
        max_score = max(max_score, score[best[i]][event]);
      }
      value += max_score;
    }
  }
};

struct Compare {
  bool operator()(Node* a, Node* b) const {
    return a->value < b->value;
  }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> N >> K >> C;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < K; j++) {
      cin >> score[i][j];
    }
  }
  priority_queue<Node*, vector<Node*>, Compare> pq;
  pq.push(new Node());
  for (int i = 0; i < K; i++) {
    Node* node = pq.top();
    pq.pop();
    for (int count_forced = node->count_forced; count_forced < K; count_forced++) {
      pq.push(new Node(node, count_forced));
    }
    if (i + 1 == K) {
      cout << node->value << "\n";
    }
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -