Submission #1070921

# Submission time Handle Problem Language Result Execution time Memory
1070921 2024-08-22T20:53:57 Z codexistent Ice Hockey World Championship (CEOI15_bobek) C++14
0 / 100
284 ms 22008 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 45
#define FOR(i, a, b) for(ll i = a; i <= b; i++)

ll n, c, m[MAXN], r = 1;

int main(){
    cin >> n >> c;
    FOR(i, 1, n) cin >> m[i];
    sort(m + 1, m + 1 + n);

    if(n == 1) {
        cout << (m[1] <= c) << endl;
        return 0;
    }

    pair<ll, ll> a = {1, (1 + n) / 2}, b = {(1 + n) / 2 + 1, n};

    // solve first half
    ll mska = pow(2, a.second - a.first + 1);
    vector<ll> msa;
    FOR(msk, 1, mska - 1){
        ll s = 0;
        FOR(i, a.first, a.second){
            if(msk & (1 << (i - a.first))){
                s += m[i];
            }
        }

        if(s > c) continue;
        r++;
        msa.push_back(s);
    }
    sort(begin(msa), end(msa));

    // solve second half
    ll mskb = pow(2, b.second - b.first + 1);
    vector<ll> msb;
    FOR(msk, 1, mskb - 1){
        ll s = 0;
        FOR(i, b.first, b.second){
            if(msk & (1 << (i - b.first))){
                s += m[i];
            }
        }

        if(s > c) continue;
        r++;
        msb.push_back(s);
    }
    sort(begin(msb), end(msb));

    // combine both halves
    /*ll ptr = (ll)msa.size() - 1;
    FOR(i, 0, (ll)msb.size() - 1){
        while(ptr != -1 && msa[ptr] + msb[i] > c) {
            ptr--;
        }

        r += ptr + 1;
    }*/

    cout << r << endl;
}

/*
8 1232
143 321241 53 1532 123 3253 32513 1232
*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 2372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 2828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 4408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 16556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 284 ms 22008 KB Output isn't correct
2 Halted 0 ms 0 KB -