Submission #66042

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

using namespace std;
#define ll long long

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

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 <= 21) {
        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;
        set<ll> did;
        map<ll,int> did1;
        map<ll,int> did2;
        for(int mask = 0; mask < (1<<20); mask++) {
            ll money = m;
            for(int i = 0; i < 20; i++) {
                if(mask&(1<<i)) {
                    money-= c[i];
                }
            }
            if(money >= 0) {
                did1[m-money]++;
                did.insert(m-money);
            }
        }
        ll prev = -1;
        for(int el : did) {
            if(prev != -1) {
                did2[el] = prev = did1[el]+prev;
            } else {
                did2[el] = prev = did1[el];
            }
        }
        for(int mask = 0; mask < (1<<(n-20)); mask++) {
            ll money = m;
            for(int i = 20; i < n; i++) {
                if(mask&(1<<(i-20))) {
                    money-= c[i];
                }
            }
            if(money >= 0) {
                auto it = did.upper_bound(money);
                if(it != did.begin()) {
                    it--;
                    ways+= did2[*it];
                }
            }
        }
        cout << ways;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 488 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 652 KB Output is correct
4 Correct 2 ms 652 KB Output is correct
5 Correct 3 ms 652 KB Output is correct
6 Correct 3 ms 680 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 680 KB Output is correct
2 Correct 6 ms 680 KB Output is correct
3 Correct 12 ms 680 KB Output is correct
4 Correct 2 ms 680 KB Output is correct
5 Correct 6 ms 680 KB Output is correct
6 Correct 83 ms 680 KB Output is correct
7 Correct 12 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 680 KB Output is correct
2 Correct 21 ms 680 KB Output is correct
3 Correct 6 ms 680 KB Output is correct
4 Correct 8 ms 680 KB Output is correct
5 Correct 83 ms 680 KB Output is correct
6 Correct 11 ms 680 KB Output is correct
7 Correct 13 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 577 ms 3564 KB Output is correct
2 Execution timed out 1067 ms 31360 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 651 ms 31360 KB Output is correct
2 Execution timed out 1083 ms 31360 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 34708 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 62184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 62184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 62184 KB Time limit exceeded
2 Halted 0 ms 0 KB -