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 int long long
#define sp << ' ' <<
#define nl << '\n'
vector<int> create(vector<int> a, bool sorted){
int n = a.size();
const int LIM = 1<<n;
int sum[LIM] = {0};
vector<int> res = {0};
for(int i=1; i<LIM; ++i){
int last = 0;
for(int j=0; j<n; ++j) if((1<<j)&i) last = j;
sum[i] = sum[i^(1<<last)] + a[last];
res.push_back(sum[i]);
}
if(sorted) sort(res.begin(), res.end());
return res;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, m; cin >> n >> m;
vector<int> a(n/2), b(n-n/2);
for(int i=0; i<n/2; ++i) cin >> a[i];
for(int i=n/2; i<n; ++i) cin >> b[i-n/2];
vector<int> c = create(a, false), d = create(b, true);
int ans = 0;
for(int i : c){
if(i<=m){
auto f = upper_bound(d.begin(), d.end(), m-i);
ans += f-d.begin();
}
}
cout << ans;
}
# | 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... |