이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |