Submission #388269

#TimeUsernameProblemLanguageResultExecution timeMemory
388269leakedOlympiads (BOI19_olympiads)C++14
100 / 100
90 ms14872 KiB
#include <bits/stdc++.h> //#pra #define sz(x) (int)x.size() #define vec vector #define pb push_back #define rall(x) x.rbegin(),x.rend() #define all(x) x.begin(),x.end() #define pii pair<int,int> #define f first #define s second using namespace std; const int N=5e2+3; typedef unsigned long long ull; auto rnd=bind(uniform_int_distribution<long long>(1,1e18),mt19937(time(0))); ull r[N]; int a[N][6]; int k; int func(const array<int,6> &vc){ int s=0; for(int i=0;i<k;i++){ int mx=0; for(int j=0;j<k;j++){ mx=max(mx,a[vc[j]][i]); } s+=mx; } return s; }; signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // ifstream cin("input.txt"); int n,c; cin>>n>>k>>c; // vec<vec<int>>a(n,vec<int>(k)); vec<vec<int>>p(k,vec<int>(n)),obr(n,vec<int>(k)); for(int i=0;i<n;i++){ for(int j=0;j<k;j++){ cin>>a[i][j]; } // cerr<<i<<endl; } for(int i=0;i<k;i++){ auto cmp=[&](int x,int y){ return a[x][i]>a[y][i]; }; iota(all(p[i]),0); sort(all(p[i]),cmp); for(int j=0;j<n;j++){ obr[p[i][j]][i]=j; } } priority_queue<pair<int,array<int,6>>>pq; /// to push; { set<int>st; for(int i=0;i<k;i++) st.insert(p[i][0]); for(int i=0;i<n;i++){ if(sz(st)<k) st.insert(i); } array<int,6>lel; for(int i=0;i<k;i++){ lel[i]=*st.begin(); st.erase(st.begin()); } pq.push({func(lel),lel}); } for(int i=0;i<n;i++) r[i]=rnd(); map<ull,int>mp; while(!pq.empty()){ auto v=pq.top();pq.pop(); ull hs=0; for(int i=0;i<k;i++){ hs^=r[v.s[i]]; } if(mp.count(hs)) continue; mp[hs]=1; c--; // cerr<<v.f<<endl; if(c==0){ cout<<v.f<<endl; return 0; } auto arr=v.s; for(int chng=0;chng<k;chng++){ for(int w=0;w<k;w++){ for(int j=0;j<k;j++){ if(obr[arr[w]][j]==n-1) continue; int nw=p[j][obr[arr[w]][j]+1]; bool ok=1; for(int t=0;t<k;t++){ if(t!=chng && arr[t]==nw) ok=0; } if(ok){ int prv=arr[chng]; arr[chng]=nw; pq.push({func(arr),arr}); arr[chng]=prv; } } } } } assert(false); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...