답안 #66064

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

using namespace std;
#define ll long long

//14:20
int n;
ll m;
ll c[45];
ll way[2150000];
unordered_map<ll,int> compr;
vector<ll> did;

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;
        int b1 = 19;
        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 = 0;
        ll prev = -1;
        for(ll el : did) {
            way[in++]++;
            prev = el;
        }
        for(int i = 0; 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()) {
                    ways+= way[it-did.begin()-1];
                }
            }
        }
        cout << ways;
    }
    return 0;
}

Compilation message

bobek.cpp: In function 'int main()':
bobek.cpp:51:12: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
         ll prev = -1;
            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 356 KB Output is correct
2 Correct 3 ms 392 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 544 KB Output is correct
2 Correct 6 ms 544 KB Output is correct
3 Correct 12 ms 544 KB Output is correct
4 Correct 2 ms 544 KB Output is correct
5 Correct 7 ms 544 KB Output is correct
6 Correct 80 ms 552 KB Output is correct
7 Correct 11 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 592 KB Output is correct
2 Correct 20 ms 592 KB Output is correct
3 Correct 6 ms 592 KB Output is correct
4 Correct 7 ms 592 KB Output is correct
5 Correct 81 ms 720 KB Output is correct
6 Correct 11 ms 720 KB Output is correct
7 Correct 11 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 8888 KB Output is correct
2 Correct 152 ms 8888 KB Output is correct
3 Correct 766 ms 8892 KB Output is correct
4 Correct 137 ms 9080 KB Output is correct
5 Correct 78 ms 9080 KB Output is correct
6 Correct 88 ms 9080 KB Output is correct
7 Correct 40 ms 9080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 9080 KB Output is correct
2 Correct 116 ms 9080 KB Output is correct
3 Correct 265 ms 9080 KB Output is correct
4 Correct 2 ms 9080 KB Output is correct
5 Correct 71 ms 9080 KB Output is correct
6 Correct 97 ms 9080 KB Output is correct
7 Correct 40 ms 9080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 9080 KB Output is correct
2 Correct 209 ms 9080 KB Output is correct
3 Correct 197 ms 9080 KB Output is correct
4 Correct 24 ms 9080 KB Output is correct
5 Correct 112 ms 9080 KB Output is correct
6 Correct 363 ms 9080 KB Output is correct
7 Correct 60 ms 9080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 493 ms 9080 KB Output is correct
2 Correct 128 ms 9080 KB Output is correct
3 Correct 111 ms 9080 KB Output is correct
4 Correct 5 ms 9080 KB Output is correct
5 Correct 75 ms 9080 KB Output is correct
6 Correct 264 ms 9180 KB Output is correct
7 Correct 48 ms 9180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 9180 KB Output is correct
2 Correct 143 ms 9180 KB Output is correct
3 Correct 108 ms 9180 KB Output is correct
4 Correct 109 ms 9180 KB Output is correct
5 Correct 124 ms 9180 KB Output is correct
6 Correct 118 ms 9180 KB Output is correct
7 Correct 201 ms 9180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 616 ms 9180 KB Output is correct
2 Correct 107 ms 9180 KB Output is correct
3 Correct 102 ms 9180 KB Output is correct
4 Correct 888 ms 9180 KB Output is correct
5 Correct 158 ms 9180 KB Output is correct
6 Correct 99 ms 9180 KB Output is correct
7 Correct 40 ms 9180 KB Output is correct