Submission #238674

# Submission time Handle Problem Language Result Execution time Memory
238674 2020-06-12T10:17:07 Z grt Olympiads (BOI19_olympiads) C++17
100 / 100
58 ms 10772 KB
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 500+10;
int n,k,c;
int score[nax][6];
bool selected[nax];

struct Team {
	int cost;
	vi taken;
	vi status;
	bool operator < (const Team &T) const {
		return cost < T.cost;
	}
};

Team find_best_team(vi arr) {
	Team ans;
	ans.cost = 0;
	ans.taken = {};
	ans.status = arr;
	for(int i = 0; i < n; ++i) {
		selected[i] = 0;
		if(arr[i] == 1) {
			ans.taken.PB(i);
			selected[i] = 1;
		}
	}
	for(int j = (int)ans.taken.size(); j < k; ++j) {
		pi mx = {-1,-1};
		for(int i = 0; i < n; ++i) {
			if(arr[i] == 0 && !selected[i]) {
				mx = max(mx, {score[i][j], i});
			}
		}
		if(mx.ST == -1) {
			ans.cost = -1;
			return ans;
		}
		ans.taken.PB(mx.ND);
		selected[mx.ND] = 1;
	}
	for(int i = 0; i < 6; ++i) {
		int mx = -1;
		for(int x : ans.taken) mx = max(mx,score[x][i]);
		ans.cost += mx;
	}
	return ans;
}

priority_queue<Team>q;

int solve() {
	vi em(n);
	for(int i = 0; i < n; ++i) em[i] = 0;
	q.push(find_best_team(em));
	while(!q.empty()) {
		Team tm = q.top();
		q.pop();
		//~ for(int x : tm.status) cout << x << " ";
		//~ cout << ": " << tm.cost << "\n";
		c--;
		if(c == 0) {
			return tm.cost;
		}
		vi arr = tm.status;
		for(int i = 0; i < k; ++i) {
			if(i > 0) {
				arr[tm.taken[i-1]] = 1;
			}
			if(arr[tm.taken[i]] == 1) continue;
			arr[tm.taken[i]] = -1;
			Team tmp = find_best_team(arr);
			if(tmp.cost != -1) {
				q.push(tmp);
			}
		}
	}
	return -1;
}

int main() {_
	cin >> n >> k >> c;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < k; ++j) {
			cin >> score[i][j];
		}
	}
	cout << solve();
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 512 KB Output is correct
2 Correct 13 ms 512 KB Output is correct
3 Correct 13 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 768 KB Output is correct
2 Correct 8 ms 512 KB Output is correct
3 Correct 11 ms 1024 KB Output is correct
4 Correct 10 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 512 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 41 ms 7032 KB Output is correct
4 Correct 43 ms 6648 KB Output is correct
5 Correct 35 ms 7032 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 512 KB Output is correct
2 Correct 13 ms 512 KB Output is correct
3 Correct 13 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 9 ms 768 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 11 ms 1024 KB Output is correct
8 Correct 10 ms 768 KB Output is correct
9 Correct 14 ms 512 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 41 ms 7032 KB Output is correct
12 Correct 43 ms 6648 KB Output is correct
13 Correct 35 ms 7032 KB Output is correct
14 Correct 8 ms 640 KB Output is correct
15 Correct 19 ms 1792 KB Output is correct
16 Correct 30 ms 5112 KB Output is correct
17 Correct 58 ms 10772 KB Output is correct
18 Correct 30 ms 4600 KB Output is correct
19 Correct 13 ms 384 KB Output is correct