Submission #256536

#TimeUsernameProblemLanguageResultExecution timeMemory
256536BlagojceOlympiads (BOI19_olympiads)C++11
100 / 100
102 ms4472 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...