Submission #374225

#TimeUsernameProblemLanguageResultExecution timeMemory
374225MilosMilutinovicIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
546 ms8812 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++; } 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]; } int bot=0,top=(int)all.size()-1,pos=0; ll need=m-sum; while(bot<=top){ int mid=bot+top>>1; if(all[mid]<=need)pos=mid+1,bot=mid+1; else top=mid-1; } ans+=pos; if(sum<=m)ans++; } printf("%lld",ans); }

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:36:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |             int mid=bot+top>>1;
      |                     ~~~^~~~
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...