# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
374225 | MilosMilutinovic | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 546 ms | 8812 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |