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>
#define int long long
#define lowval(x) (x & (-x))
#define lowind __builtin_ctzll
using namespace std;
const int MAXN = 40 + 3;
int n, m, c[MAXN], dp[(1 << (MAXN >> 1))], pd[(1 << (MAXN >> 1))], ans;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> c[i];
for (int i = 1; i < (1 << (n >> 1)); i++) dp[i] = c[lowind(i)] + dp[i - lowval(i)];
for (int i = 1; i < (1 << (n - (n >> 1))); i++) pd[i] = c[lowind(i) + (n >> 1)] + pd[i - lowval(i)];
sort(dp, dp + (1 << (n >> 1)));
sort(pd, pd + (1 << (n - (n >> 1))));
for (int i = 0, j = (1 << (n - (n >> 1))) - 1; i < (1 << (n >> 1)); i++) {
while (~j && pd[j] + dp[i] > m) j--;
ans += j + 1;
}
cout << ans;
return 0;
}
# | 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... |