Submission #66056

# Submission time Handle Problem Language Result Execution time Memory
66056 2018-08-09T13:13:13 Z bazsi700 Ice Hockey World Championship (CEOI15_bobek) C++14
60 / 100
1000 ms 127436 KB
#include <bits/stdc++.h>

using namespace std;
#define ll long long

//14:20
int n;
ll m;
ll c[45];
ll way[2150000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }
    if(n <= 22) {
        ll ways = 0;
        for(int mask = 0; mask < (1<<n); mask++) {
            ll money = m;
            for(int i = 0; i < n; i++) {
                if(mask&(1<<i)) {
                    money-= c[i];
                }
            }
            if(money >= 0) {
                ways++;
            }
        }
        cout << ways;
    } else {
        ll ways = 0;
        vector<ll> did;
        map<ll,int> compr;
        int b1 = 21;
        for(int mask = 0; mask < (1<<b1); mask++) {
            ll money = m;
            for(int i = 0; i < b1; i++) {
                if(mask&(1<<i)) {
                    money-= c[i];
                }
            }
            if(money >= 0) {
                did.push_back(m-money);
            }
        }
        sort(did.begin(),did.end());
        int in = 1;
        ll prev = -1;
        for(ll el : did) {
            if(el != prev) {
                way[in]++;
                compr[el] = in++;
                prev = el;
            } else {
                way[in-1]++;
            }
        }
        for(int i = 1; i <= in; i++) {
            way[i]+=way[i-1];
        }
        for(int mask = 0; mask < (1<<(n-b1)); mask++) {
            ll money = m;
            for(int i = b1; i < n; i++) {
                if(mask&(1<<(i-b1))) {
                    money-= c[i];
                }
            }
            if(money >= 0) {
                auto it = upper_bound(did.begin(),did.end(),money);
                if(it != did.begin()) {
                    it--;
                    ways+= way[compr[*it]];
                }
            }
        }
        cout << ways;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 488 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 3 ms 580 KB Output is correct
5 Correct 3 ms 628 KB Output is correct
6 Correct 3 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 628 KB Output is correct
2 Correct 8 ms 628 KB Output is correct
3 Correct 11 ms 628 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 6 ms 736 KB Output is correct
6 Correct 81 ms 736 KB Output is correct
7 Correct 12 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 764 KB Output is correct
2 Correct 20 ms 764 KB Output is correct
3 Correct 8 ms 764 KB Output is correct
4 Correct 7 ms 764 KB Output is correct
5 Correct 79 ms 764 KB Output is correct
6 Correct 11 ms 764 KB Output is correct
7 Correct 12 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 18256 KB Output is correct
2 Correct 632 ms 45432 KB Output is correct
3 Execution timed out 1055 ms 56268 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 394 ms 56268 KB Output is correct
2 Correct 492 ms 56268 KB Output is correct
3 Correct 468 ms 56268 KB Output is correct
4 Correct 2 ms 56268 KB Output is correct
5 Correct 282 ms 56268 KB Output is correct
6 Correct 433 ms 56268 KB Output is correct
7 Correct 169 ms 56268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 600 ms 56268 KB Output is correct
2 Correct 637 ms 56268 KB Output is correct
3 Correct 628 ms 56268 KB Output is correct
4 Correct 20 ms 56268 KB Output is correct
5 Correct 298 ms 56268 KB Output is correct
6 Correct 527 ms 56268 KB Output is correct
7 Correct 170 ms 56268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 121280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 127436 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 127436 KB Time limit exceeded
2 Halted 0 ms 0 KB -