Submission #374224

#TimeUsernameProblemLanguageResultExecution timeMemory
374224MilosMilutinovicIce Hockey World Championship (CEOI15_bobek)C++14
20 / 100
550 ms8664 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=45;
ll a[N];
int main(){
    int n;scanf("%i",&n);
    ll m;scanf("%lld",&m);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    int b=n/2;
    vector<ll> all;
    ll ans=1;
    for(int i=1;i<(1<<b);i++){
        ll sum=0LL;
        for(int j=0;j<b;j++){
            if(i&(1<<j))sum+=a[j];
        }
        all.pb(sum);
        if(sum<=m)ans++;
        //printf("%lld\n",sum);
    }
    sort(all.begin(),all.end());
    int sz=n-b;
    auto Get=[&](ll x){
        if(x>m)return 0;
        return (int)(lower_bound(all.begin(),all.end(),m-x)-all.begin());
    };
    for(int i=1;i<(1<<sz);i++){
        ll sum=0LL;
        for(int j=0;j<sz;j++){
            if(i&(1<<j))sum+=a[b+j];
        }
        //printf("%lld\n",sum);
        ans+=Get(sum);
        if(sum<=m)ans++;
    }
    printf("%lld",ans);
}

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:8:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     int n;scanf("%i",&n);
      |           ~~~~~^~~~~~~~~
bobek.cpp:9:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |     ll m;scanf("%lld",&m);
      |          ~~~~~^~~~~~~~~~~
bobek.cpp:10:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |     for(int i=0;i<n;i++)scanf("%lld",&a[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...