Submission #256536

# Submission time Handle Problem Language Result Execution time Memory
256536 2020-08-02T19:59:56 Z Blagojce Olympiads (BOI19_olympiads) C++11
100 / 100
102 ms 4472 KB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
 
const int i_inf = 1e9;
const ll inf = 1e17;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 502;

int n, k, c;
int a[mxn][6];

bool vis[10000][mxn];
vector<int> v[10000];
int forced[10000];

int ans(int added, int p){
	int cnt = 0;
	fr(i, 0, n){
		if(vis[p][i] || find(all(v[p]), i) != v[p].end()) continue;
		++cnt;
	}
	if(cnt < k-added){
		return -i_inf;
	}
	
	int res = 0;
	fr(j, added, k){	
		int best = -1, mx = -1; 
		fr(i, 0, n){
			if(vis[p][i] || find(all(v[p]), i) != v[p].end()) continue;
			if(a[i][j] > mx){
				mx = a[i][j];
				best = i;
			}
		}
		v[p].pb(best);
	}
	
	fr(i, 0, k){
		int mx = 0;
		for(auto u : v[p]) mx = max(mx, a[u][i]);
		res += mx;
	}
	return res;
	
}

int search(){
	int pos = 0;
	int ret = 0;
	int processed = 0;
	
	pq<pair<int, int> > Q;
	
	Q.push({ans(0, 0), 0});
	
	while(processed < c){
		int curr = Q.top().nd;
		ret = Q.top().st;
		Q.pop();
		++processed;
		vector<int> tempv;
		fr(i, 0, forced[curr]) tempv.pb(v[curr][i]);
		fr(i, forced[curr], (int)v[curr].size()){
			
			memcpy(vis[++pos], vis[curr], sizeof(vis[curr]));
			vis[pos][v[curr][i]] = true;
			v[pos] = tempv;
			forced[pos] = tempv.size();
			Q.push({ans(forced[pos], pos), pos});
			tempv.pb(v[curr][i]);
		}
	}
	return ret;
}

void solve(){
	cin >> n >> k >> c;
	fr(i, 0, n){
		fr(j, 0, k){
			cin >> a[i][j];
		}
	}
	cout<<search()<<endl;
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1664 KB Output is correct
2 Correct 14 ms 1664 KB Output is correct
3 Correct 14 ms 1664 KB Output is correct
4 Correct 10 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Correct 8 ms 3200 KB Output is correct
4 Correct 7 ms 2696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1664 KB Output is correct
2 Correct 12 ms 1664 KB Output is correct
3 Correct 61 ms 3448 KB Output is correct
4 Correct 60 ms 3320 KB Output is correct
5 Correct 21 ms 2048 KB Output is correct
6 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1664 KB Output is correct
2 Correct 14 ms 1664 KB Output is correct
3 Correct 14 ms 1664 KB Output is correct
4 Correct 10 ms 1664 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 8 ms 3200 KB Output is correct
8 Correct 7 ms 2696 KB Output is correct
9 Correct 15 ms 1664 KB Output is correct
10 Correct 12 ms 1664 KB Output is correct
11 Correct 61 ms 3448 KB Output is correct
12 Correct 60 ms 3320 KB Output is correct
13 Correct 21 ms 2048 KB Output is correct
14 Correct 6 ms 2688 KB Output is correct
15 Correct 23 ms 2048 KB Output is correct
16 Correct 42 ms 2936 KB Output is correct
17 Correct 102 ms 4472 KB Output is correct
18 Correct 42 ms 2808 KB Output is correct
19 Correct 11 ms 1664 KB Output is correct