Submission #850870

# Submission time Handle Problem Language Result Execution time Memory
850870 2023-09-17T15:18:42 Z serifefedartar Olympiads (BOI19_olympiads) C++17
100 / 100
30 ms 5144 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 505;

vector<vector<int>> p;
int N, K, C;
struct Rule {
	vector<pair<int,int>> r;
	int res;

	Rule(vector<pair<int,int>> rl) {
		r = rl;
		res = 0;
		for (int i = 0; i < N; i++) {
			if (r[i].f == 2)
				r[i].f = 0;
		}

		set<int> taken;
		set<int> choice;
		for (int i = 0; i < N; i++) {
			if (r[i].f == 1) {
				taken.insert(i);
				choice.insert(r[i].s);
			}
		}

		for (int i = 0; i < K; i++) {
			if (choice.count(i) != 0)
				continue;

			int mx = 0;
			int mx_ind = -1;
			for (int j = 0; j < N; j++) {
				if (r[j].f == 0 && mx <= p[j][i]) {
					mx = p[j][i];
					mx_ind = j;
				}
			}
			if (mx_ind != -1) {
				taken.insert(mx_ind);
				r[mx_ind] = {2, i};
			}
		}

		if (taken.size() != K)
			res = -1;
		else {
			for (int i = 0; i < K; i++) {
				int mx_here = 0;
				for (auto u : taken)
					mx_here = max(mx_here, p[u][i]);
				res += mx_here;
			}
		}
	}
};

bool operator <(Rule A, Rule B) {
		return A.res < B.res;
}

int main() {
	fast
	cin >> N >> K >> C;

	p = vector<vector<int>>(N, vector<int>(K));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < K; j++)
			cin >> p[i][j];
	}

	priority_queue<Rule> pq;
	vector<pair<int,int>> emp(N, {0, -1});
	Rule new_rule = Rule(emp);
	pq.push(new_rule);

	while (true) {
		Rule now = pq.top();
		pq.pop();
		C--;

		if (C == 0) {
			cout << now.res << "\n";
			exit(0);
		}

		vector<pair<int,int>> R = now.r;
		for (int i = 0; i < N; i++) {
			if (R[i].f == 2) {
				R[i] = {-1, R[i].s};
				new_rule = Rule(R);
				if (new_rule.res != -1)
					pq.push(new_rule);
				R[i] = {1, R[i].s};
			}
		}
	}
}

Compilation message

olympiads.cpp: In constructor 'Rule::Rule(std::vector<std::pair<int, int> >)':
olympiads.cpp:53:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |   if (taken.size() != K)
      |       ~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 580 KB Output is correct
2 Correct 15 ms 708 KB Output is correct
3 Correct 18 ms 604 KB Output is correct
4 Correct 10 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 860 KB Output is correct
2 Correct 5 ms 432 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 4 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Output is correct
2 Correct 15 ms 348 KB Output is correct
3 Correct 24 ms 1276 KB Output is correct
4 Correct 22 ms 1120 KB Output is correct
5 Correct 24 ms 1376 KB Output is correct
6 Correct 4 ms 496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 580 KB Output is correct
2 Correct 15 ms 708 KB Output is correct
3 Correct 18 ms 604 KB Output is correct
4 Correct 10 ms 348 KB Output is correct
5 Correct 6 ms 860 KB Output is correct
6 Correct 5 ms 432 KB Output is correct
7 Correct 5 ms 600 KB Output is correct
8 Correct 4 ms 452 KB Output is correct
9 Correct 15 ms 600 KB Output is correct
10 Correct 15 ms 348 KB Output is correct
11 Correct 24 ms 1276 KB Output is correct
12 Correct 22 ms 1120 KB Output is correct
13 Correct 24 ms 1376 KB Output is correct
14 Correct 4 ms 496 KB Output is correct
15 Correct 30 ms 5144 KB Output is correct
16 Correct 22 ms 604 KB Output is correct
17 Correct 21 ms 860 KB Output is correct
18 Correct 24 ms 1192 KB Output is correct
19 Correct 13 ms 620 KB Output is correct