Submission #500895

# Submission time Handle Problem Language Result Execution time Memory
500895 2022-01-01T15:30:27 Z jesus_coconut Olympiads (BOI19_olympiads) C++17
100 / 100
86 ms 16924 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back();
#define all(a) begin(a), end(a)
using namespace std;

using ll = long long;
using pii = pair<int, int>;

int const N = 505;
int const K = 6;
int const C = 2005;
int n, k, c;
int a[N][K];

vector<array<int, N>> state;
vector<array<pair<int, bool>, K>> taken;

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

bool getBest(int p) {
	set<int> outs;
	for (int j = 0; j < k; ++j) {
		if (!taken[p][j].S) {
			taken[p][j].F = -1;
			outs.insert(-1);
			for (int i = 0; i < n; ++i) {
				if (state[p][i] == 0 && !outs.count(i)) {
					if (taken[p][j].F == -1 || a[taken[p][j].F][j] < a[i][j]) {
						outs.erase(taken[p][j].F);
						taken[p][j].F = i;
						outs.insert(i);
					}
				}
			}
			if (outs.count(-1)) return false;
		}
	}
	return true;
}

int getCost(int p) {
	int ret =0;
	for (int j = 0; j < k; ++j) {
		int cur = INT_MIN;
		for (int i = 0; i < k; ++i) {
			cur = max(cur, a[taken[p][i].F][j]);
		}
		ret += cur;
	}
	return ret;
}

void solve() {
	priority_queue<pii> pq;
	state.eb(0);
	taken.eb(0);
	getBest(0);
	pq.emplace(getCost(0), 0);
	int p = 0;
	for (int i = 1; i < c; ++i) {
		auto [cost, q] = pq.top();
		pq.pop();
		for (int j = 0; j < k; ++j) {
			if (!taken[q][j].S) {
				++p;
				state.eb(0);
				taken.eb(0);
				state.back() = state[q];
				taken.back() = taken[q];
				for (int l = 0; l < j; ++l) {
					if (!taken[q][l].S) {
						state.back()[taken[q][l].F] = 1;
						taken.back()[l].S = true;
					}
				}
				state.back()[taken[q][j].F] = -1;
				if (getBest(p)) {
					pq.emplace(getCost(p), p);
				}
			}
		}
	}
	cout << pq.top().F << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	load();
	solve();

	return 0;
}

Compilation message

olympiads.cpp: In function 'void solve()':
olympiads.cpp:65:11: warning: statement has no effect [-Wunused-value]
   65 |  state.eb(0);
      |          ~^~
olympiads.cpp:66:11: warning: statement has no effect [-Wunused-value]
   66 |  taken.eb(0);
      |          ~^~
olympiads.cpp:76:14: warning: statement has no effect [-Wunused-value]
   76 |     state.eb(0);
      |             ~^~
olympiads.cpp:77:14: warning: statement has no effect [-Wunused-value]
   77 |     taken.eb(0);
      |             ~^~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4480 KB Output is correct
2 Correct 11 ms 8576 KB Output is correct
3 Correct 9 ms 4460 KB Output is correct
4 Correct 8 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 7 ms 8576 KB Output is correct
3 Correct 15 ms 16780 KB Output is correct
4 Correct 9 ms 8548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4444 KB Output is correct
2 Correct 8 ms 4456 KB Output is correct
3 Correct 48 ms 16852 KB Output is correct
4 Correct 52 ms 16916 KB Output is correct
5 Correct 15 ms 8576 KB Output is correct
6 Correct 9 ms 8560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4480 KB Output is correct
2 Correct 11 ms 8576 KB Output is correct
3 Correct 9 ms 4460 KB Output is correct
4 Correct 8 ms 4480 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 7 ms 8576 KB Output is correct
7 Correct 15 ms 16780 KB Output is correct
8 Correct 9 ms 8548 KB Output is correct
9 Correct 9 ms 4444 KB Output is correct
10 Correct 8 ms 4456 KB Output is correct
11 Correct 48 ms 16852 KB Output is correct
12 Correct 52 ms 16916 KB Output is correct
13 Correct 15 ms 8576 KB Output is correct
14 Correct 9 ms 8560 KB Output is correct
15 Correct 16 ms 8644 KB Output is correct
16 Correct 43 ms 16888 KB Output is correct
17 Correct 86 ms 16924 KB Output is correct
18 Correct 34 ms 8656 KB Output is correct
19 Correct 10 ms 4480 KB Output is correct