# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101761 | rocketninja7 | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 234 ms | 16860 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 <cstdio>
#include <algorithm>
using namespace std;
int main(){
int N;
long long int M;
scanf("%d%lld", &N, &M);
long long int A[N];
for(int i=0;i<N;i++){
scanf("%lld", &A[i]);
}
long long int sums1[1<<(N/2)];
for(int i=0;i<(1<<(N/2));i++){
sums1[i]=1000000000000000001;
long long int temp=0;
long long int tempI=i;
while(tempI>0){
temp+=A[__builtin_ctz(tempI)];
if(temp>M){
break;
}
tempI-=tempI&-tempI;
}
if(temp<=M){
sums1[i]=temp;
}
}
long long int sums2[1<<(N-N/2)];
for(int i=0;i<(1<<(N-N/2));i++){
sums2[i]=1000000000000000001;
long long int temp=0;
long long int tempI=i;
while(tempI>0){
temp+=A[__builtin_ctz(tempI)+N/2];
if(temp>M){
break;
}
tempI-=tempI&-tempI;
}
if(temp<=M){
sums2[i]=temp;
}
}
sort(sums1, sums1+(1<<(N/2)));
sort(sums2, sums2+(1<<(N-N/2)));
long long int ans=0;
int ri=(1<<(N-N/2))-1;
for(int i=0;i<(1<<(N/2));i++){
while(ri>-1&&sums1[i]+sums2[ri]>M){
ri--;
}
ans+=ri+1;
}
printf("%lld", ans);
return 0;
}
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... |