Submission #725788

# Submission time Handle Problem Language Result Execution time Memory
725788 2023-04-18T04:24:34 Z browntoad Olympiads (BOI19_olympiads) C++14
44 / 100
29 ms 3360 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 = {0, -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;
            }
        }
        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--){
        assert(pq.size()>=1);
        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;
            assert(i<tmp.cho.size());
            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
*/

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from olympiads.cpp:1:
olympiads.cpp: In function 'int main()':
olympiads.cpp:113:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<pp>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |             assert(i<tmp.cho.size());
      |                    ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1492 KB Output is correct
2 Correct 19 ms 1772 KB Output is correct
3 Correct 15 ms 1344 KB Output is correct
4 Correct 11 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1876 KB Output is correct
2 Correct 3 ms 704 KB Output is correct
3 Correct 7 ms 3360 KB Output is correct
4 Correct 7 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2076 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1492 KB Output is correct
2 Correct 19 ms 1772 KB Output is correct
3 Correct 15 ms 1344 KB Output is correct
4 Correct 11 ms 612 KB Output is correct
5 Correct 5 ms 1876 KB Output is correct
6 Correct 3 ms 704 KB Output is correct
7 Correct 7 ms 3360 KB Output is correct
8 Correct 7 ms 2260 KB Output is correct
9 Correct 29 ms 2076 KB Output is correct
10 Runtime error 1 ms 468 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -