Submission #726140

#TimeUsernameProblemLanguageResultExecution timeMemory
726140browntoadOlympiads (BOI19_olympiads)C++14
100 / 100
91 ms78924 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast", "unroll-loops") using namespace std; #define ll long long #define int ll #define FOR(i,a,b) for (int i = (a); i<(b); i++) #define REP(i,n) FOR(i,0,n) #define REP1(i,n) FOR(i,1,n+1) #define RREP(i,n) for (int i=(n)-1; i>=0; i--) #define f first #define s second #define pb push_back #define ALL(x) x.begin(),x.end() #define SZ(x) (int)(x.size()) #define SQ(x) (x)*(x) #define pii pair<int, int> #define pip pair<int, pii> #define pdd pair<double ,double> #define pcc pair<char, char> #define endl '\n' //#define TOAD #ifdef TOAD #define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl #define IOS() #else #define bug(...) #define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #endif const ll inf = 1ll<<60; const ll iinf = 2147483647; const ll mod = 1e9+7; const ll maxn=2e5+5; const ll maxm=105; const double PI=acos(-1); ll pw(ll x, ll p, ll m=mod){ ll ret=1; while (p>0){ if (p&1){ ret*=x; ret%=m; } x*=x; x%=m; p>>=1; } return ret; } ll inv(ll a, ll m=mod){ return pw(a,m-2,m); } int n, k, c; struct pp{ int arr[6]; }; struct tup{ int val; vector<pp> cho; // size k int cid; bool operator < (const tup &b)const{ return val<b.val; } }; pair<int, vector<pp>> opt(vector<pp> &cur){ pair<int, vector<pp>> ret; vector<bool> occ(SZ(cur)); ret.f = 0; REP(i, k){ pii mx = {-1, -1}; int rmx = 0; REP(j, SZ(cur)){ rmx = max(rmx, cur[j].arr[i]); if (!occ[j] && cur[j].arr[i]>mx.f){ mx.f = cur[j].arr[i]; mx.s = j; } } //assert(mx.s != -1); ret.f+=rmx; ret.s.pb(cur[mx.s]); occ[mx.s] = 1; } REP(i, SZ(cur)){ if (!occ[i]) ret.s.pb(cur[i]); } return ret; } signed main(){ IOS(); cin>>n>>k>>c; priority_queue<tup> pq; vector<pp> vc(n); REP(i, n) { REP(j, k) { cin>>vc[i].arr[j]; } } pair<int, vector<pp> > a = opt(vc); pq.push({a.f, a.s, -1}); tup tp; while(c--){ tp = pq.top(); pq.pop(); // cout<<tp.val<<' '<<tp.cho.size()<<' '<<tp.cid<<endl; if (k == SZ(tp.cho)){ continue; // done } FOR(i, tp.cid+1, k){ tup tmp = tp; tmp.cid = i-1; tmp.cho.erase(tmp.cho.begin()+i); pair<int, vector<pp> > aa = opt(tmp.cho); tmp.val = aa.f; tmp.cho = aa.s; pq.push(tmp); } } cout<<tp.val<<endl; } /* 5 1 2 1 2 2 6 2 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...