답안 #66052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66052 2018-08-09T13:10:46 Z bazsi700 Ice Hockey World Championship (CEOI15_bobek) C++14
60 / 100
1000 ms 65700 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;
        unordered_map<ll,int> compr;
        int b1 = 20;
        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) {
            way[in]++;
            //if(el != prev) {
                compr[el] = in++;
                prev = el;
            //}
        }
        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;
}

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 3 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 356 KB Output is correct
2 Correct 2 ms 392 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 5 ms 516 KB Output is correct
6 Correct 3 ms 516 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 632 KB Output is correct
2 Correct 9 ms 632 KB Output is correct
3 Correct 12 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 8 ms 652 KB Output is correct
6 Correct 83 ms 652 KB Output is correct
7 Correct 13 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 652 KB Output is correct
2 Correct 24 ms 652 KB Output is correct
3 Correct 8 ms 652 KB Output is correct
4 Correct 8 ms 652 KB Output is correct
5 Correct 94 ms 652 KB Output is correct
6 Correct 12 ms 652 KB Output is correct
7 Correct 13 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 17760 KB Output is correct
2 Correct 425 ms 30936 KB Output is correct
3 Execution timed out 1079 ms 41536 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 252 ms 41536 KB Output is correct
2 Correct 296 ms 41536 KB Output is correct
3 Correct 385 ms 41536 KB Output is correct
4 Correct 3 ms 41536 KB Output is correct
5 Correct 176 ms 41536 KB Output is correct
6 Correct 253 ms 41536 KB Output is correct
7 Correct 83 ms 41536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 363 ms 41536 KB Output is correct
2 Correct 441 ms 41536 KB Output is correct
3 Correct 416 ms 41536 KB Output is correct
4 Correct 24 ms 41536 KB Output is correct
5 Correct 197 ms 41536 KB Output is correct
6 Correct 383 ms 41536 KB Output is correct
7 Correct 91 ms 41536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 65496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 65564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1052 ms 65700 KB Time limit exceeded
2 Halted 0 ms 0 KB -