답안 #66046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66046 2018-08-09T13:05:27 Z bazsi700 Ice Hockey World Championship (CEOI15_bobek) C++14
40 / 100
1000 ms 42952 KB
#include <bits/stdc++.h>

using namespace std;
#define ll long long

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

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;
        unordered_map<ll,int> compr;
        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) {
                did.insert(m-money);
            }
        }
        int in = 1;
        for(ll el : did) {
            compr[el] = in++;
        }
        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) {
                way[compr[(m-money)]]++;
            }
        }
        for(int i = 1; i <= in; i++) {
            way[i]+=way[i-1];
        }
        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+= way[compr[*it]];
                }
            }
        }
        cout << ways;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 488 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 568 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Correct 3 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 568 KB Output is correct
2 Correct 6 ms 568 KB Output is correct
3 Correct 12 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 7 ms 612 KB Output is correct
6 Correct 77 ms 740 KB Output is correct
7 Correct 12 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 740 KB Output is correct
2 Correct 20 ms 740 KB Output is correct
3 Correct 7 ms 740 KB Output is correct
4 Correct 7 ms 740 KB Output is correct
5 Correct 79 ms 740 KB Output is correct
6 Correct 11 ms 740 KB Output is correct
7 Correct 11 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 2412 KB Output is correct
2 Execution timed out 1073 ms 28616 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 433 ms 28616 KB Output is correct
2 Execution timed out 1073 ms 28616 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1076 ms 31724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 42952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 42952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 42952 KB Time limit exceeded
2 Halted 0 ms 0 KB -