Submission #909958

#TimeUsernameProblemLanguageResultExecution timeMemory
909958MilosMilutinovicOlympiads (BOI19_olympiads)C++14
100 / 100
102 ms14416 KiB
#include<bits/stdc++.h> #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;} template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;} ll readint(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,k,c,v[505][10],ord[10][505],pos[10][505]; bool was[505]; bool good(vector<int> v){ bool ret=true; for(int i:v){ if(was[i]) ret=false; was[i]=true; } for(int i:v) was[i]=false; return ret; } int score(vector<int> v){ vector<int> mx(k+1); for(int i:v){ for(int j=1;j<=k;j++) mx[j]=max(mx[j],::v[i][j]); } int ret=0; for(int i=1;i<=k;i++) ret+=mx[i]; return ret; } int main() { n=readint(); k=readint(); c=readint(); for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) v[i][j]=readint(); for(int j=1;j<=k;j++){ for(int i=1;i<=n;i++) ord[j][i]=i; sort(ord[j]+1,ord[j]+n+1,[&](int a,int b){return v[a][j]>v[b][j];}); for(int i=1;i<=n;i++) pos[j][ord[j][i]]=i; } vector<int> v; for(int j=1;j<=k;j++){ for(int i=1;i<=n;i++){ v.pb(ord[j][i]); if(!good(v)) v.pop_back(); else break; } } sort(v.begin(),v.end()); map<vector<int>,bool> was; was[v]=true; vector<int> res; set<pair<int,vector<int>>> st; st.emplace(score(v),v); while(res.size()<c){ auto it=prev(st.end()); vector<int> v=it->second; st.erase(it); res.pb(score(v)); for(int i=1;i<=k;i++){ for(int j=1;j<=k;j++){ vector<int> nv; for(int z=1;z<=k;z++){ if(i!=z) nv.pb(v[z-1]); else if(pos[j][v[z-1]]!=n) nv.pb(ord[j][pos[j][v[z-1]]+1]); } sort(nv.begin(),nv.end()); if(nv.size()==k&&good(nv)){ if(!was[nv]){ was[nv]=true; st.emplace(score(nv),nv); } } } } } sort(res.rbegin(),res.rend()); printf("%d\n",res[c-1]); return 0; }

Compilation message (stderr)

olympiads.cpp: In function 'int main()':
olympiads.cpp:71:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |  while(res.size()<c){
      |        ~~~~~~~~~~^~
olympiads.cpp:84:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   84 |     if(nv.size()==k&&good(nv)){
      |        ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...