Submission #544834

#TimeUsernameProblemLanguageResultExecution timeMemory
544834skittles1412Olympiads (BOI19_olympiads)C++17
0 / 100
9 ms596 KiB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

const int maxn = 505;

struct Sol {
	int w, meq;
	array<int, 6> ans;
	vector<int> neq;

	bool operator<(const Sol& s) const {
		return w < s.w;
	}
};

int n, m, arr[maxn][6];

int opt(int ind, const vector<int>& ign) {
	bool bad[n] {};
	for (auto& a : ign) {
		bad[a] = true;
	}
	pair<int, int> ans {};
	for (int i = 0; i < n; i++) {
		if (!bad[i]) {
			ans = max(ans, pair<int, int> {arr[i][ind], i});
		}
	}
	return ans.second;
}

vector<Sol> fracture(const Sol& s) {
	vector<Sol> ans;
	for (int i = s.meq; i < m; i++) {
		vector<int> cneq = s.neq;
		cneq.insert(cneq.end(), s.ans.begin(), s.ans.begin() + i);
		int w = 0;
		array<int, 6> cur {};
		copy(s.ans.begin(), s.ans.begin() + i, cur.begin());
		for (int j = i; j < m; j++) {
			if (sz(cneq) >= n) {
				goto loop;
			}
			cur[j] = opt(j, cneq);
			cneq.push_back(cur[j]);
		}
		for (int j = 0; j < m; j++) {
			w += arr[cur[j]][j];
		}
		if (i == s.meq) {
			cneq = s.neq;
			cneq.push_back(cur[i]);
		} else {
			cneq = {cur[i]};
		}
		ans.push_back(Sol {
			w,
			i,
			cur,
			cneq
		});
	loop:;
	}
	return ans;
}

Sol iopt() {
	int w = 0;
	array<int, 6> cur {};
	vector<int> neq;
	for (int i = 0; i < m; i++) {
		cur[i] = opt(i, neq);
		neq.push_back(cur[i]);
		w += arr[cur[i]][i];
	}
	return {w, 0, cur, {cur[0]}};
}

void solve() {
	int k;
	cin >> n >> m >> k;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> arr[i][j];
		}
	}
	priority_queue<Sol> pq;
	pq.push(iopt());
	for (int i = 0; i < k - 1; i++) {
		auto x = pq.top();
		pq.pop();
		for (auto& a : fracture(x)) {
			pq.push(a);
		}
	}
	cout << pq.top().w << endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...