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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define coutpair(p) cout << p.first << " " << p.second << "|"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m; cin >> n >> m;
int szn = n/2, szm = n-szn;
ll fi[szn], se[szm];
for (int i=0; i<szn; i++) cin >> fi[i];
for (int i=0; i<szm; i++) cin >> se[i];
vector<ll> v;
for (int i=0; i<(1<<szn); i++){
ll cursum = 0;
for (int j=0; j<szn; j++){
if (i&(1<<j) != 0) cursum += fi[j];
}
v.push_back(cursum);
}
sort(v.begin(), v.end());
ll ans = 0;
for (int i=0; i<(1<<szm); i++){
ll cursum = 0;
for (int j=0; j<szm; j++){
if (i&(1<<j) != 0) cursum += se[j];
}
ll ways = upper_bound(v.begin(), v.end(), m-cursum) - v.begin();
ans += ways;
}
cout << ans;
return 0;
}
Compilation message (stderr)
bobek.cpp: In function 'int main()':
bobek.cpp:37:26: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
37 | if (i&(1<<j) != 0) cursum += fi[j];
| ~~~~~~~^~~~
bobek.cpp:48:26: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
48 | if (i&(1<<j) != 0) cursum += se[j];
| ~~~~~~~^~~~
# | 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... |