#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
void open_file(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
// const int maxN;
void solve() {
int n, mx;
cin >> n >> mx;
int arr[n + 1];
for (int i = 1; i <= n; i++)
cin >> arr[i];
vector<int> a, b, sums;
for (int i = 1; i <= n / 2; i++)
a.push_back(arr[i]);
for (int i = n / 2 + 1; i <= n; i++)
b.push_back(arr[i]);
int m = a.size(); ll cur;
for (int i = 0; i < (1 << m); i++) {
cur = 0;
for (int j = 0; j < m; j++) {
if (i & (1 << j)) cur += a[j];
if (cur > mx) break;
} if (cur <= mx)
sums.push_back(cur);
} sort(sums.begin(), sums.end());
m = b.size(); ll ans = 0;
for (int i = 0; i < (1 << m); i++) {
cur = 0;
for (int j = 0; j < m; j++) {
if (i & (1 << j)) cur += b[j];
if (cur > mx) break;
} ans += lower_bound(sums.begin(), sums.end(), mx - cur + 1) - sums.begin();
} cout << ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
Compilation message
bobek.cpp: In function 'void open_file(std::string)':
bobek.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen((filename + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bobek.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen((filename + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
992 KB |
Output is correct |
2 |
Correct |
75 ms |
2520 KB |
Output is correct |
3 |
Correct |
305 ms |
10656 KB |
Output is correct |
4 |
Correct |
69 ms |
2772 KB |
Output is correct |
5 |
Correct |
11 ms |
1244 KB |
Output is correct |
6 |
Correct |
5 ms |
732 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1500 KB |
Output is correct |
2 |
Correct |
23 ms |
992 KB |
Output is correct |
3 |
Correct |
139 ms |
5584 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
736 KB |
Output is correct |
6 |
Correct |
11 ms |
992 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
1500 KB |
Output is correct |
2 |
Correct |
127 ms |
2520 KB |
Output is correct |
3 |
Correct |
110 ms |
2516 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
56 ms |
2520 KB |
Output is correct |
6 |
Correct |
181 ms |
8908 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
227 ms |
5076 KB |
Output is correct |
2 |
Correct |
20 ms |
992 KB |
Output is correct |
3 |
Correct |
6 ms |
736 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
736 KB |
Output is correct |
6 |
Correct |
126 ms |
6200 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
992 KB |
Output is correct |
2 |
Correct |
68 ms |
2520 KB |
Output is correct |
3 |
Correct |
7 ms |
736 KB |
Output is correct |
4 |
Correct |
6 ms |
736 KB |
Output is correct |
5 |
Correct |
67 ms |
2576 KB |
Output is correct |
6 |
Correct |
14 ms |
992 KB |
Output is correct |
7 |
Correct |
5 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
10332 KB |
Output is correct |
2 |
Correct |
22 ms |
992 KB |
Output is correct |
3 |
Correct |
7 ms |
736 KB |
Output is correct |
4 |
Correct |
303 ms |
10504 KB |
Output is correct |
5 |
Correct |
92 ms |
6100 KB |
Output is correct |
6 |
Correct |
10 ms |
1040 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |