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 mod 1000000007
const int maxn = 45;
int a[maxn];
int n, m;
int ans = 0;
vector<int>v;
void s1(int i, int sum){
if(i == (n / 2) + 1){
v.push_back(sum);
return;
}
s1(i + 1, sum);
s1(i + 1, sum + a[i]);
}
void s2(int i, int sum){
if(i == n){
auto it = upper_bound(v.begin(), v.end(), m - sum) - v.begin();
ans += it;
return;
}
s2(i + 1, sum);
s2(i + 1, sum + a[i]);
}
signed main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
s1(0, 0);
s2((n / 2) + 1, 0);
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... |