답안 #196839

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
196839 2020-01-17T06:46:05 Z Fischer Olympiads (BOI19_olympiads) C++14
0 / 100
111 ms 21244 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
int n, k, c;
int p[510][6];

struct Partition {
	vector<int> choice;
	vector<int> best;
	int cost;
	Partition(vector<int> A): choice(A) {
		vector<int> temp(k, 0);
		int cnt = 0;
		for (int i = 0; i < n; ++i) {
			if (choice[i] == 1) {
				best.push_back(i);
				for (int j = 0; j < k; ++j) {
					temp[j] = max(temp[j], p[i][j]);
				}
				cnt += 1;
			}
		}
		for (int i = cnt; i < k; ++i) {
			int mx = -1, id;
			for (int j = 0; j < n; ++j) {
				if (choice[j] == 0 and mx < p[j][i]) {
					mx = p[j][i];
					id = j;
				}
			}
			choice[id] = 1;
			best.push_back(id);
			for (int j = 0; j < k; ++j) {
				temp[j] = max(temp[j], p[id][j]);
			}
		}
		for (int i = 0; i < k; ++i) choice[best[i]] = 0;
		cost = accumulate(all(temp), 0);
	}

	bool operator <(Partition r) const{ 
		return cost < r.cost;
	}
};

int main() {
	cin >> n >> k >> c;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < k; ++j) {
			cin >> p[i][j];
		}
	}
	priority_queue<Partition> Q;
	Q.push(Partition(vector<int>(n, 0)));
	while (c--) {
		auto q = Q.top(); Q.pop();
		if (c == 0) {
			cout << q.cost << endl;
			break;
		}
		if (count_if(all(q.choice), 
			[](int x) {return x >= 0;}) == k) {
				continue;
		}
		for (int i = 0; i < k; ++i) {
			vector<int> choice = q.choice;		
			vector<int> best = q.best;
			choice[best[i]] = -1;
			for (int j = 0; j < i; ++j) {
				choice[best[j]] = 1;
			}
			Q.push(Partition(choice));
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 4600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 3092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 21208 KB Output is correct
2 Correct 90 ms 21244 KB Output is correct
3 Incorrect 111 ms 21088 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 4600 KB Output isn't correct
2 Halted 0 ms 0 KB -