# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101753 | cheeheng | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 406 ms | 20944 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;
long long A[45];
int main(){
int N; long long M;
scanf("%d%lld", &N, &M);
for(int i = 0; i < N; i ++){
scanf("%lld", &A[i]);
}
if(N <= 20){
vector<long long> sum1;
for(int i = 0; i < (1<<N); i ++){
long long temp = 0;
for(int j = 0; j < N; j ++){
if(i&(1<<j)){
temp += A[j];
}
}
sum1.push_back(temp);
}
sort(sum1.begin(), sum1.end());
printf("%lld", (long long)(upper_bound(sum1.begin(), sum1.end(), M)-sum1.begin()));
}else{
vector<long long> sum1;
for(int i = 0; i < (1<<20); i ++){
long long temp = 0;
for(int j = 0; j < 20; j ++){
if(i&(1<<j)){
temp += A[j];
}
}
sum1.push_back(temp);
}
vector<long long> sum2;
for(int i = 0; i < (1<<(N-20)); i ++){
long long temp = 0;
for(int j = 0; j < (N-20); j ++){
if(i&(1<<j)){
temp += A[j+20];
}
}
sum2.push_back(temp);
}
sort(sum1.begin(), sum1.end());
sort(sum2.begin(), sum2.end());
long long ans = 0;
for(int i = 0; i < (1<<20); i ++){
ans += upper_bound(sum2.begin(), sum2.end(), M-sum1[i])-sum2.begin();
}
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... |