#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));
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<5;++i)cout<<lefts[i][0]<<' '<<lefts[i][1]<<'\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;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
11248 KB |
Output is correct |
2 |
Correct |
117 ms |
11244 KB |
Output is correct |
3 |
Correct |
113 ms |
11456 KB |
Output is correct |
4 |
Correct |
108 ms |
11248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1463 ms |
75384 KB |
Output is correct |
2 |
Correct |
1393 ms |
63396 KB |
Output is correct |
3 |
Correct |
1289 ms |
44276 KB |
Output is correct |
4 |
Correct |
1365 ms |
59752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
540 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
11248 KB |
Output is correct |
2 |
Correct |
117 ms |
11244 KB |
Output is correct |
3 |
Correct |
113 ms |
11456 KB |
Output is correct |
4 |
Correct |
108 ms |
11248 KB |
Output is correct |
5 |
Correct |
1463 ms |
75384 KB |
Output is correct |
6 |
Correct |
1393 ms |
63396 KB |
Output is correct |
7 |
Correct |
1289 ms |
44276 KB |
Output is correct |
8 |
Correct |
1365 ms |
59752 KB |
Output is correct |
9 |
Runtime error |
540 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |