# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40952 | wzy | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 604 ms | 21464 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 <stdio.h>
#include <vector>
#include <stdint.h>
#include <algorithm>
using namespace std;
#define pb push_back
#define int long long
int ans = 1 , v1[50] , v2[50] , n , m;
int32_t main(){
scanf("%lld%lld" , &n , &m);
int sz1 = n / 2 , sz2 = n - sz1;
for(int i = 0 ; i < n;i++){
if(sz1){
scanf("%lld" , &v1[n/2 - sz1]);
sz1--;
}
else{
scanf("%lld" , &v2[(n - n/2) - sz2]);
sz2--;
}
}
vector<int> value1 , value2;
sz1 = n/2 , sz2 = n - sz1;
for(int i = 1 ; i < (1<<sz1) ; i++){
int sum = 0;
for(int j = 0 ; j < n ; j++){
if(1<<j & i) sum += v1[j];
}
if(sum <= m)
value1.pb(sum);
}
for(int i = 1 ; i < (1<<sz2) ; i++){
int sum = 0;
for(int j = 0 ; j < n ; j++){
if(1<<j & i) sum += v2[j];
}
if(sum <= m)
value2.pb(sum);
}
ans += value1.size() + value2.size();
sort(value1.begin() , value1.end());
sort(value2.begin() , value2.end());
for(int i = 0 ; i < value1.size() ; i++){
int l = 0 , r = (int)value2.size() - 1;
int ansj = -1;
while(l<= r){
int mid = (l+r)/2;
if(value2[mid] + value1[i] <= m){
l = mid + 1;
ansj = max(ansj , mid);
}
else r = mid - 1;
}
if(ansj != -1) ans += ansj + 1;
}
printf("%lld\n" , 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... |