This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 40;
int N; ll M;
ll A[N_MAX + 2];
vector <ll> getAll (int l, int r) {
vector <ll> ret;
for (int mask = 0; mask < (1 << (r - l + 1)); mask++) {
ll sum = 0;
for (int i = 0; i < r - l + 1; i++) {
if ((mask >> i) & 1) {
sum += A[l + i];
}
}
ret.push_back(sum);
}
return ret;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++) {
cin >> A[i];
}
vector <ll> lv = getAll(1, N / 2);
vector <ll> rv = getAll(N / 2 + 1, N);
sort(lv.begin(), lv.end());
sort(rv.begin(), rv.end());
ll answer = 0;
for (int l = 0, r = (int) rv.size() - 1; l < (int) lv.size(); l++) {
while (r >= 0 && lv[l] + rv[r] > M) {
r--;
}
answer += r - 0 + 1;
}
cout << answer << "\n";
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... |