#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define ALL(X) X.begin(),X.end()
#define SZ(X) (int)X.size()
#define MAXN 1001000
#define INF 1e9
int N,K,C;
int mem[510][10];
vi cur;
vector<pi> st;
vi out;
int cntr;
int lefts[2010][3];
int rights[2010][3];
bool safe[2001000];
int ind;
map<ll,ll> M;
ll hh(){
ll ans=0;ll mult = 1;
while(SZ(cur)){
ans += mult * cur.back();
cur.pop_back();
mult *= N;
}
return ans;
}
void rec2(int stt, int en){
if (SZ(cur) == en-stt+1){
++cntr;
int ans = 0;
// for (auto i : cur)cout<<i<<' ';cout<<'\n';
for (int i=stt;i<en;++i){
int t=0;
for (int j=1;j<SZ(cur);++j)t=max(t,mem[cur[j]][i]);
ans += t;
}
// cout<<ans<<'\n';
st.pb(ans,cntr);
return;
}
int lst = cur.back()+1;
for (int i=lst;i<=N;++i){
cur.pb(i);
rec2(stt,en);
cur.pop_back();
}
}
void rec3(int stt, int en, bool flag){
if (SZ(cur) == en-stt+1){
++cntr;
// cout<<cntr<<' '<<safe[cntr]<<'\n';
if (safe[cntr] == 0)return;
int ans = 0;
for (int i=1;i<SZ(cur);++i){
if (flag)lefts[ind][i-1] = cur[i];
else rights[ind][i-1] = cur[i];
}
++ind;
return;
}
int lst = cur.back()+1;
for (int i=lst;i<=N;++i){
cur.pb(i);
rec3(stt,en,flag);
cur.pop_back();
}
}
int main(){
// freopen("in.txt","r",stdin);
cin>>N>>K>>C;
for (int i=1;i<=N;++i)for (int j=0;j<K;++j)cin>>mem[i][j];
cur.pb(0);
rec2(0,K/2);
sort(ALL(st));
reverse(ALL(st));
while(SZ(st) > C)st.pop_back();
for (auto i :st)safe[i.s]=1;
cntr=0;
rec3(0,K/2,1);
cntr=ind=0;
st.clear();
memset(safe,0,sizeof(safe));
// cout<<K/2<<' '<<K<<'\n';
rec2(K/2,K);
sort(ALL(st));
reverse(ALL(st));
// for (auto i : st)cout<<i.f<<' '<<i.s<<'\n';
while(SZ(st) > C)st.pop_back();
for (auto i :st)safe[i.s]=1;
cntr=0;
rec3(K/2,K,0);
// for (int i=0;i<C;++i)cout<<lefts[i][0]<<' '<<lefts[i][1]<<' '<<lefts[i][2]<<'\n';
for (int i=0;i<C;++i){
if (lefts[i][0] == 0)break;
for (int j=0;j<C;++j){
if (rights[j][0] ==0)break;
cur.clear();
cur.pb(lefts[i][0]);
if (lefts[i][1] != 0)cur.pb(lefts[i][1]);
if (lefts[i][2] != 0)cur.pb(lefts[i][2]);
cur.pb(rights[j][0]);
if (rights[j][1] != 0)cur.pb(rights[j][1]);
if (rights[j][2] != 0)cur.pb(rights[j][2]);
sort(ALL(cur));
cur.resize(unique(ALL(cur)) - cur.begin());
// if (SZ(cur) < K)continue;
// for (auto x:cur)cout<<x<<' ';cout<<'\n';
int ans=0;
for (int i=0;i<K;++i){
int t=0;
for (int j=0;j<SZ(cur);++j)t=max(t,mem[cur[j]][i]);
ans += t;
}
M[hh()]=ans;
}
}
for (auto i : M)out.pb(i.s);
sort(ALL(out));
cout<<out[SZ(out) - C];
}
Compilation message
olympiads.cpp: In function 'void rec3(int, int, bool)':
olympiads.cpp:68:13: warning: unused variable 'ans' [-Wunused-variable]
int ans = 0;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
11376 KB |
Output is correct |
2 |
Correct |
92 ms |
11400 KB |
Output is correct |
3 |
Correct |
93 ms |
11504 KB |
Output is correct |
4 |
Correct |
89 ms |
11376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1783 ms |
92704 KB |
Output is correct |
2 |
Correct |
1631 ms |
69968 KB |
Output is correct |
3 |
Incorrect |
1488 ms |
48860 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
528 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
11376 KB |
Output is correct |
2 |
Correct |
92 ms |
11400 KB |
Output is correct |
3 |
Correct |
93 ms |
11504 KB |
Output is correct |
4 |
Correct |
89 ms |
11376 KB |
Output is correct |
5 |
Correct |
1783 ms |
92704 KB |
Output is correct |
6 |
Correct |
1631 ms |
69968 KB |
Output is correct |
7 |
Incorrect |
1488 ms |
48860 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |