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 int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
map<int, int> M;
map<int, int> M2;
int tab[49];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, Sum;
cin >> n >> Sum;
for(int i=0;i<n;i++) {
cin >> tab[i];
}
int m = n/2;
if(n==1) {
if(tab[0]<=Sum) {
cout << "2\n";
} else {
cout << "1\n";
}
return 0;
}
int m2 = n-m;
for(int i=0;i<(1<<m);i++) {
int s = 0;
for(int j=0;j<m;j++) {
if(i&(1<<j)) {
s+=tab[j];
}
}
M[-s]++;
}
for(int i=0;i<(1<<m2);i++) {
int s = 0;
for(int j=m;j<n;j++) {
if(i&(1<<(j-m))) {
s+=tab[j];
}
}
M2[s]++;
}
int s = 0;
auto it = M2.begin();
int ans = 0;
for(pii x:M) {
x.st = -x.st;
int val = Sum-x.st;
while(it!=M2.end()&&(*it).st<=val) {
s += (*it).nd;
it++;
}
ans += x.nd*s;
}
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... |