답안 #134245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134245 2019-07-22T09:12:07 Z dvdg6566 Olympiads (BOI19_olympiads) C++14
13 / 100
2000 ms 93660 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> 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;

set<pi> st;
vi out;
int cntr;
int lefts[20010][4];
int rights[20010][4];
int benson[3000001];
int ind;
map<ll,int> 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){
        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;
        }
        ++benson[ans];
        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, int t){
    if (SZ(cur) == en-stt+1){
        int ans = 0;
        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;
        }
        if (ans<t)return;
        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,t);
        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);
    int run=0;int ix=3000000;
    // for (int i=0;i<21;++i)cout<<benson[i]<<' ';cout<<'\n';
    while(run<C&&ix>0){
        --ix;
        run += benson[ix];
    }
    // cout<<ix<<'\n';
    rec3(0,K/2,1,ix);
    memset(benson,0,sizeof(benson));
    rec2(K/2,K);
    ind=0;ix=0;run=3000000;
    while(run<C&&ix>0){
        --ix;
        run += benson[ix];
    }
    // cerr<<l<<' '<<u<<'\n';
    rec3(K/2,K,0,ix);
    // cout<<ind<<'\n';
    // for (int i=0;i<C+2;++i)cout<<lefts[i][0]<<' '<<lefts[i][1]<<' '<<lefts[i][2]<<'\n';
    // for (int i=0;i<C+2;++i)cout<<rights[i][0]<<' '<<rights[i][1]<<' '<<rights[i][2]<<'\n';
    for (int i=0;i<2*C;++i){
        if (lefts[i][0] == 0)break;
        for (int j=0;j<2*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];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 20596 KB Output is correct
2 Correct 143 ms 20728 KB Output is correct
3 Correct 145 ms 20596 KB Output is correct
4 Correct 145 ms 20596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2048 ms 93660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 609 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 20596 KB Output is correct
2 Correct 143 ms 20728 KB Output is correct
3 Correct 145 ms 20596 KB Output is correct
4 Correct 145 ms 20596 KB Output is correct
5 Execution timed out 2048 ms 93660 KB Time limit exceeded
6 Halted 0 ms 0 KB -