#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 200007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
vector <ll> v;
ll n, m, a[50], ans;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; ++i) cin >> a[i];
for(int mask = 0; mask < (1 << (n / 2)); ++mask){
ll sum = 0;
for(int i = 0; i < n / 2; ++i) if((mask >> i) & 1) sum += a[i];
v.pb(sum);
}
sort(all(v));
for(int mask = 0; mask < (1 << ((n + 1) / 2)); ++mask){
ll sum = 0;
for(int i = n / 2; i < n; ++i) if((mask >> (i - n / 2)) & 1) sum += a[i];
ans += upper_bound(all(v), m - sum) - v.begin();
}
cout << ans << endl;
return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
232 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
848 KB |
Output is correct |
2 |
Correct |
97 ms |
2504 KB |
Output is correct |
3 |
Correct |
441 ms |
8680 KB |
Output is correct |
4 |
Correct |
92 ms |
2504 KB |
Output is correct |
5 |
Correct |
16 ms |
976 KB |
Output is correct |
6 |
Correct |
8 ms |
592 KB |
Output is correct |
7 |
Correct |
12 ms |
912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
1460 KB |
Output is correct |
2 |
Correct |
29 ms |
976 KB |
Output is correct |
3 |
Correct |
174 ms |
4636 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
7 ms |
592 KB |
Output is correct |
6 |
Correct |
15 ms |
976 KB |
Output is correct |
7 |
Correct |
13 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
1484 KB |
Output is correct |
2 |
Correct |
156 ms |
2504 KB |
Output is correct |
3 |
Correct |
142 ms |
2400 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
105 ms |
2460 KB |
Output is correct |
6 |
Correct |
213 ms |
8632 KB |
Output is correct |
7 |
Correct |
69 ms |
2504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
4468 KB |
Output is correct |
2 |
Correct |
27 ms |
976 KB |
Output is correct |
3 |
Correct |
11 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
7 ms |
720 KB |
Output is correct |
6 |
Correct |
148 ms |
4528 KB |
Output is correct |
7 |
Correct |
12 ms |
976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
848 KB |
Output is correct |
2 |
Correct |
86 ms |
2480 KB |
Output is correct |
3 |
Correct |
11 ms |
644 KB |
Output is correct |
4 |
Correct |
9 ms |
592 KB |
Output is correct |
5 |
Correct |
110 ms |
2504 KB |
Output is correct |
6 |
Correct |
17 ms |
848 KB |
Output is correct |
7 |
Correct |
215 ms |
8584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
354 ms |
8624 KB |
Output is correct |
2 |
Correct |
34 ms |
848 KB |
Output is correct |
3 |
Correct |
9 ms |
592 KB |
Output is correct |
4 |
Correct |
448 ms |
8632 KB |
Output is correct |
5 |
Correct |
154 ms |
4548 KB |
Output is correct |
6 |
Correct |
14 ms |
848 KB |
Output is correct |
7 |
Correct |
25 ms |
1460 KB |
Output is correct |