제출 #522792

#제출 시각아이디문제언어결과실행 시간메모리
522792LucaDantasOlympiads (BOI19_olympiads)C++17
0 / 100
2085 ms89480 KiB
// Vai dar TLE
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 510;

int n, k, C;

struct ct {
	int a[6];
	void read() { for(int i = 0; i < k; i++) scanf("%d", a+i); }
} AAA[maxn];

struct PQ {
	vector<int> ids;
	int val, index;

	PQ(vector<int> _ids={}, int _val=0, int _index=0) : ids(_ids), val(_val), index(_index) {}
	bool operator<(const PQ& o) const { return val < o.val; }
};

int get(vector<int> id, int lim) {
	int ans = 0;
	for(int i = 0; i <= lim; i++) {
		int aq = 0;
		for(int x : id)
			aq = max(aq, AAA[x].a[i]);
		ans += aq;
	}
	return ans;
}

int mx[6], best;

void db(vector<int> v) { putchar('{'); for(int x : v) printf(" %d", x); puts(" }"); }

map<vector<int>,bool> mark;

int main() {
	scanf("%d %d %d", &n, &k, &C);
	
	for(int i = 0; i < n; i++) {
		AAA[i].read();

		for(int j = 0; j < k; j++)
			mx[j] = max(mx[j], AAA[i].a[j]);
	}

	for(int j = 0; j < k; j++)
		best += mx[j];

	priority_queue<PQ> pq;
	pq.push(PQ({}, best, 0));

	int cnt = 0;
	while(1) {
		auto [ids, val, index] = pq.top(); pq.pop();

		if(index == k) {
			sort(ids.begin(), ids.end());
			if(mark[ids]) continue;
			mark[ids] = 1;
			
			++cnt;
			// db(ids);
			// printf("%d %d\n", cnt, val);
			
			if(cnt == C) {
				printf("%d\n", val);
				return 0;
			}
		}
		
		for(int i = 0; i < n; i++) {
			if(find(ids.begin(), ids.end(), i) == ids.end()) {
				ids.push_back(i);
				int v = get(ids, index), correction = 0;
				
				for(int j = index+1; j < k; j++)
					correction += mx[j];

				pq.push(PQ(ids, v+correction, index+1));
				ids.pop_back();
			}
		}
	}
}

컴파일 시 표준 에러 (stderr) 메시지

olympiads.cpp: In function 'int main()':
olympiads.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d %d %d", &n, &k, &C);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp: In member function 'void ct::read()':
olympiads.cpp:11:48: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  void read() { for(int i = 0; i < k; i++) scanf("%d", a+i); }
      |                                           ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...