#include <bits/stdc++.h>
using namespace std;
#define ll long long
//14:20
int n;
ll m;
ll c[45];
ll way[2150000];
unordered_map<ll,int> compr;
vector<ll> did;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) {
cin >> c[i];
}
if(n <= 22) {
ll ways = 0;
for(int mask = 0; mask < (1<<n); mask++) {
ll money = m;
for(int i = 0; i < n; i++) {
if(mask&(1<<i)) {
money-= c[i];
}
}
if(money >= 0) {
ways++;
}
}
cout << ways;
} else {
ll ways = 0;
int b1 = 20;
for(int mask = 0; mask < (1<<b1); mask++) {
ll money = m;
for(int i = 0; i < b1; i++) {
if(mask&(1<<i)) {
money-= c[i];
}
}
if(money >= 0) {
did.push_back(m-money);
}
}
sort(did.begin(),did.end());
int in = 1;
ll prev = -1;
for(ll el : did) {
if(el != prev) {
way[in]++;
compr[el] = in++;
prev = el;
} else {
way[in-1]++;
}
}
for(int i = 1; i <= in; i++) {
way[i]+=way[i-1];
}
for(int mask = 0; mask < (1<<(n-b1)); mask++) {
ll money = m;
for(int i = b1; i < n; i++) {
if(mask&(1<<(i-b1))) {
money-= c[i];
}
}
if(money >= 0) {
auto it = upper_bound(did.begin(),did.end(),money);
if(it != did.begin()) {
it--;
ways+= way[compr[*it]];
}
}
}
cout << ways;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
356 KB |
Output is correct |
2 |
Correct |
3 ms |
432 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
3 ms |
764 KB |
Output is correct |
5 |
Correct |
3 ms |
764 KB |
Output is correct |
6 |
Correct |
3 ms |
764 KB |
Output is correct |
7 |
Correct |
2 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
764 KB |
Output is correct |
2 |
Correct |
9 ms |
764 KB |
Output is correct |
3 |
Correct |
11 ms |
764 KB |
Output is correct |
4 |
Correct |
3 ms |
764 KB |
Output is correct |
5 |
Correct |
7 ms |
764 KB |
Output is correct |
6 |
Correct |
89 ms |
764 KB |
Output is correct |
7 |
Correct |
12 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
764 KB |
Output is correct |
2 |
Correct |
23 ms |
764 KB |
Output is correct |
3 |
Correct |
9 ms |
764 KB |
Output is correct |
4 |
Correct |
9 ms |
764 KB |
Output is correct |
5 |
Correct |
89 ms |
764 KB |
Output is correct |
6 |
Correct |
11 ms |
764 KB |
Output is correct |
7 |
Correct |
11 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
9608 KB |
Output is correct |
2 |
Correct |
352 ms |
25176 KB |
Output is correct |
3 |
Execution timed out |
1076 ms |
36924 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
211 ms |
36924 KB |
Output is correct |
2 |
Correct |
231 ms |
36924 KB |
Output is correct |
3 |
Correct |
302 ms |
36924 KB |
Output is correct |
4 |
Correct |
2 ms |
36924 KB |
Output is correct |
5 |
Correct |
139 ms |
36924 KB |
Output is correct |
6 |
Correct |
205 ms |
36924 KB |
Output is correct |
7 |
Correct |
84 ms |
36924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
281 ms |
36924 KB |
Output is correct |
2 |
Correct |
395 ms |
36924 KB |
Output is correct |
3 |
Correct |
322 ms |
36924 KB |
Output is correct |
4 |
Correct |
22 ms |
36924 KB |
Output is correct |
5 |
Correct |
156 ms |
36924 KB |
Output is correct |
6 |
Correct |
326 ms |
36924 KB |
Output is correct |
7 |
Correct |
91 ms |
36924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
65644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1083 ms |
65684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
65684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |