답안 #726140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726140 2023-04-18T14:15:41 Z browntoad Olympiads (BOI19_olympiads) C++14
100 / 100
91 ms 78924 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pip pair<int, pii>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif

const ll inf = 1ll<<60;
const ll iinf = 2147483647;
const ll mod = 1e9+7;
const ll maxn=2e5+5;
const ll maxm=105;
const double PI=acos(-1);

ll pw(ll x, ll p, ll m=mod){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=m;
        }
        x*=x;
        x%=m;
        p>>=1;
    }
    return ret;
}

ll inv(ll a, ll m=mod){
    return pw(a,m-2,m);
}

int n, k, c;
struct pp{
    int arr[6];
};
struct tup{
    int val;
    vector<pp> cho; // size k
    int cid;
    bool operator < (const tup &b)const{
        return val<b.val;
    }
};

pair<int, vector<pp>> opt(vector<pp> &cur){
    pair<int, vector<pp>> ret;
    vector<bool> occ(SZ(cur));
    ret.f = 0;
    REP(i, k){
        pii mx = {-1, -1};
        int rmx = 0;
        REP(j, SZ(cur)){
            rmx = max(rmx, cur[j].arr[i]);
            if (!occ[j] && cur[j].arr[i]>mx.f){
                mx.f = cur[j].arr[i];
                mx.s = j;
            }
        }
        //assert(mx.s != -1);
        ret.f+=rmx;
        ret.s.pb(cur[mx.s]);
        occ[mx.s] = 1;
    }
    REP(i, SZ(cur)){
        if (!occ[i]) ret.s.pb(cur[i]);
    }
    return ret;
}
signed main(){
    IOS();
    cin>>n>>k>>c;
    priority_queue<tup> pq;
    vector<pp> vc(n);
    REP(i, n) {
        REP(j, k) {
            cin>>vc[i].arr[j];
        }
    }
    pair<int, vector<pp> > a = opt(vc);
    pq.push({a.f, a.s, -1});
    tup tp;
    while(c--){
        tp = pq.top(); pq.pop();
        // cout<<tp.val<<' '<<tp.cho.size()<<' '<<tp.cid<<endl;
        if (k == SZ(tp.cho)){
            continue; // done
        }
        FOR(i, tp.cid+1, k){
            tup tmp = tp;
            tmp.cid = i-1;
            tmp.cho.erase(tmp.cho.begin()+i);
            pair<int, vector<pp> > aa = opt(tmp.cho);
            tmp.val = aa.f; tmp.cho = aa.s;
            pq.push(tmp);
        }
    }
    cout<<tp.val<<endl;
}
/*
5
1 2 1 2 2
6
2 4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1492 KB Output is correct
2 Correct 20 ms 1868 KB Output is correct
3 Correct 14 ms 1340 KB Output is correct
4 Correct 11 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1876 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 7 ms 3264 KB Output is correct
4 Correct 7 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2132 KB Output is correct
2 Correct 16 ms 852 KB Output is correct
3 Correct 91 ms 67808 KB Output is correct
4 Correct 71 ms 59432 KB Output is correct
5 Correct 23 ms 9552 KB Output is correct
6 Correct 3 ms 828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1492 KB Output is correct
2 Correct 20 ms 1868 KB Output is correct
3 Correct 14 ms 1340 KB Output is correct
4 Correct 11 ms 624 KB Output is correct
5 Correct 5 ms 1876 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 7 ms 3264 KB Output is correct
8 Correct 7 ms 2260 KB Output is correct
9 Correct 29 ms 2132 KB Output is correct
10 Correct 16 ms 852 KB Output is correct
11 Correct 91 ms 67808 KB Output is correct
12 Correct 71 ms 59432 KB Output is correct
13 Correct 23 ms 9552 KB Output is correct
14 Correct 3 ms 828 KB Output is correct
15 Correct 42 ms 15352 KB Output is correct
16 Correct 57 ms 47004 KB Output is correct
17 Correct 85 ms 78924 KB Output is correct
18 Correct 66 ms 45228 KB Output is correct
19 Correct 15 ms 980 KB Output is correct