Submission #241667

#TimeUsernameProblemLanguageResultExecution timeMemory
241667anonymousIce Hockey World Championship (CEOI15_bobek)C++14
90 / 100
1028 ms72380 KiB
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#define LL long long
using namespace std;
LL N, M, Wt[45], Ways;
unordered_map <LL, LL> Freq;
vector <pair<LL,LL> > Freq2;
int main() {
    //freopen("bobekin.txt","r",stdin);
    scanf("%lld %lld",&N,&M);
    for (int i=0; i < N; i++) {
        scanf("%lld", &Wt[i]);
    }
    for (int i=0; i < 1<<(N/2); i++) {
        LL wt = 0;
        for (int j=0; j < N/2; j++) {
            if (i & (1<<j)) {wt += Wt[j];}
        }
        if (wt <= M) {
            Freq[wt]++;
        }
    }
    for (auto p: Freq) {
        Freq2.push_back(p);
    }
    sort(Freq2.begin(), Freq2.end());
    for (int i=1; i<Freq2.size(); i++) {
        Freq2[i].second += Freq2[i-1].second;
    }

    for (int i=0; i < 1<< (N - N/2); i++) {
        LL wt = 0;
        for (int j=0; j < N - N/2; j++) {
            if (i & (1<<j)) {wt += Wt[j + N/2];}
        }
        if (wt <= M) {
            auto it = upper_bound(Freq2.begin(), Freq2.end(), pair <LL,LL> {M - wt + 1, 0});
            Ways += Freq2[it - Freq2.begin() - 1].second;
        }
    }
    printf("%lld",Ways);
}

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=1; i<Freq2.size(); i++) {
                   ~^~~~~~~~~~~~~
bobek.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~~~~~
bobek.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &Wt[i]);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...