This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
int n;
ll w, a[44];
int main() {
cin.tie(0)->sync_with_stdio(0);
//multitest([&](){});
cin >> n >> w;
vector<ll> cn;
for(int i = 0; i < n; i++) cin >> a[i];
int c = n/2;
int b = n - c;
for(int i = 0; i < 1<<c; i++) {
ll cur = 0;
for(int j = 0; j < c; j++) if((i>>j)&1) cur += a[j];
cn.push_back(cur);
}
ll ans = 0;
sort(all(cn));
for(int i = 0; i < 1<<b; i++) {
ll cur = 0;
for(int j = 0; j < b; j++) if((i>>j)&1) cur += a[c+j];
ans += upper_bound(all(cn), w-cur)-cn.begin();
}
cout << ans << '\n';
}
# | 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... |